how to fix query-tool: Query failed ERROR: syntax error at or near while inserting data - windows

I have this command to populate created tables with geographic data
COPY public.adonis_schema (id, name, batch, migration_time) FROM stdin;
1 database/migrations/1607548129188_users 1 2021-04-02 14:14:27.470863+00
2 database/migrations/1607548416832_conversations 1 2021-04-02 14:14:28.070888+00
3 database/migrations/1607548444586_participations 1 2021-04-02 14:14:28.480253+00
4 database/migrations/1607548494088_messages 1 2021-04-02 14:14:29.050234+00
5 database/migrations/1609020554140_vcard_shares 1 2021-04-02 14:14:29.520909+00
6 database/migrations/1609024583459_add_conversation_names 1 2021-04-02 14:14:29.905367+00
7 database/migrations/1609467289494_meetings 1 2021-04-02 14:14:30.300248+00
8 database/migrations/1609467351706_notes 1 2021-04-02 14:14:30.960852+00
9 database/migrations/1609976010374_meetings_lengths 1 2021-04-02 14:14:31.640233+00
10 database/migrations/1610498049695_conversations_event_ids 1 2021-04-02 14:14:32.020247+00
11 database/migrations/1611099138751_cache_users 1 2021-04-02 14:14:32.405294+00
12 database/migrations/1616628109445_conversations_ownerships 1 2021-04-02 14:14:32.800258+00
13 database/migrations/1617362496376_conversations_types 1 2021-04-02 14:14:33.185207+00
14 database/migrations/1617805023298_conversations_timestamps 2 2021-04-07 14:18:42.957427+00
47 database/migrations/1622085675952_user_is_busies 3 2021-05-27 03:22:31.964783+00
\.
I have as indicated put the entire code in a sql file and executed it with psql but I have an error:
ERROR: ERREUR: erreur de syntaxe sur ou près de « 1 »
LINE 2: 1 database/migrations/1607548129188_users 1 2021-04-02 14:14...
^
SQL state: 42601
Character: 73
Do you have an idea please?

Related

How to define ctag parser for custom file format

I regularly use a file format that doesn't have a parser for Ctags. I would like to write a parser for it, but I'm not sure how. The file format doesn't have keywords like a computer language does, but instead where you are in the file is dependent on the content of the last 10 columns of each line in the file. (Sorry, the ENDF format was created in the 1960s.)
How can I create a new parser that depends on the contents of a particular column?
Here is an abbreviated example of the file, but it still contains enough information to get the gist of what I'm trying to do:
MMMMFFTTT
33 856 176 17434 1451
34 2 155 17434 1451
34 51 115 17434 1451
0.000000+0 0.000000+0 0 0 0 07434 1 0
0.000000+0 0.000000+0 0 0 0 07434 0 0
7.418300+4 1.813790+2 0 0 1 07434 2151
7.418300+4 1.000000+0 0 0 2 07434 2151
1.000000-5 5.000000+3 1 7 0 17434 2151
0.000000+0 0.000000+0 0 3 5 07434 2151
0.000000+0 0.000000+0 2 0 24 47434 2151
7.418300+4 1.813790+2 0 0 0 07434 3 28
-7.222000+6-7.222000+6 0 0 1 397434 3 28
39 2 7434 3 28
7.261820+6 0.000000+0 9.300000+6 0.000000+0 9.600000+6 2.18585-137434 3 28
1.000000+7 5.01372-13 1.050000+7 1.32071-11 1.100000+7 8.70475-107434 3 28
0.000000+0 0.000000+0 0 0 0 07434 3 0
7.418300+4 1.813790+2 0 0 0 07434 3 37
-2.093600+7-2.093600+7 0 0 1 207434 3 37
2.105140+7 0.000000+0 2.200000+7 7.150990-5 2.400000+7 2.707920-27434 3 37
1.300000+8 5.411910-2 1.500000+8 3.895580-2 7434 3 37
0.000000+0 0.000000+0 0 0 0 07434 3 0
7.418300+4 1.813790+2 0 0 0 07434 3 41
-1.328500+7-1.328500+7 0 0 1 267434 3 41
26 2 7434 3 41
1.335820+7 0.000000+0 1.550000+7 0.000000+0 1.600000+7 2.56183-147434 3 41
1.700000+7 9.60380-12 1.800000+7 3.02742-10 1.900000+7 1.474340-77434 3 41
1.300000+8 1.582280-2 1.500000+8 1.154350-2 7434 3 41
I've labeled the columns MMMM, FF, and TT. When these change is when I need a "tag" (using the term loosely) to tell me that it has changed. Note, this is (kind of) nested in that, there are many TTs in each FF, and many FFs inside each MMMM.
I'm not sure what the tag output should look like. I've never even looked at the tag output; I've always relied on someone else to parse them for me. Please assist this novice as I try to learn.
I wrote a syntax parser for Vim several years ago and was hoping this might be a good addition.
My answer assumes you use Universal-ctags (https://ctags.io).
I expect you know the basic concept of ctags: kinds and fields. See https://docs.ctags.io/en/latest/man/ctags.1.html#tag-entries if you don't know them.
I expect you know the output format of ctags. See https://docs.ctags.io/en/latest/man/tags.5.html if you don't know.
There are various ways to implement a parser in ctags. In this case, you may want to write the parser in C language with line-oriented way.
33 856 176 17434 1451
34 2 155 17434 1451
...
You may expect the 7434 at the first line is tagged as mmmm.
However you may not expect the 7434 at the second line.
The parser must have an ability to track the state of input; the parser should not make a tag of which name is already tagged.
It means you cannot define the parser for the language in your .ctags with regular expressions. You may have to write it in C.
The inpue is line oriented. So you can use readLineFromInputFile function. It is the heart of line oriented parser.
https://github.com/masatake/ctags/commit/e8e0015393ae7a3b447ee886bd0884f45d11ced2 is a runnable example illustrating how to use readLineFromInputFile.
With the example, ctags emits following tags output:
$ ctags --options=NONE --list-kinds=ENDF
m materials
f material files
t material subdivisions
$ ctags --options=NONE --sort=no -o - input.endf
434 input.endf /^ 33 856 176 17434 1451$/;" m
14 input.endf /^ 33 856 176 17434 1451$/;" f mat:434
51 input.endf /^ 33 856 176 17434 1451$/;" t mf:434 14
...

pandas: time difference in groupby

How to calculate time difference for each id between current row and next for
dataset below:
time id
2012-03-16 23:50:00 1
2012-03-16 23:56:00 1
2012-03-17 00:08:00 1
2012-03-17 00:10:00 2
2012-03-17 00:12:00 2
2012-03-17 00:20:00 2
2012-03-20 00:43:00 3
and get next result:
time id tdiff
2012-03-16 23:50:00 1 6
2012-03-16 23:56:00 1 12
2012-03-17 00:08:00 1 NA
2012-03-17 00:10:00 2 2
2012-03-17 00:12:00 2 8
2012-03-17 00:20:00 2 NA
2012-03-20 00:43:00 3 NA
I see that you need result in minutes by id. Here is how to do it :
use diff() in groupby :
# first convert to datetime with the right format
data['time']=pd.to_datetime(data.time, format='%Y-%m-%d %H:%M:%S')
data['tdiff']=(data.groupby('id').diff().time.values/60000000000).astype(int)
data['tdiff'][data['tdiff'] < 0] = np.nan
print(data)
output
time id tdiff
0 2012-03-16 23:50:00 1 NaN
1 2012-03-16 23:56:00 1 6.0
2 2012-03-17 00:08:00 1 12.0
3 2012-03-17 00:10:00 2 NaN
4 2012-03-17 00:12:00 2 2.0
5 2012-03-17 00:20:00 2 8.0
6 2012-03-20 00:43:00 3 NaN

Laravel groupby id get newest records

I have :
ID | BRAND_ID | CUST_ID | EXPIRY_DATE | CREATED_DATE
1 1 22 2018-02-02 2018-01-01 00:00:00
2 1 22 2018-02-02 2018-02-02 00:00:00
3 1 22 2019-02-02 2018-02-02 00:05:00
4 1 22 2019-02-02 2018-02-02 00:05:00
5 1 22 2018-02-02 2018-02-02 00:07:00
6 1 22 2018-02-02 2018-02-02 00:07:00
trying to get the last newest records grouping by custid
->groupBy('CUST_ID')
->ordrBy('CREATED_DATE', 'desc')
but i'm getting the first 2 rows when i add groupBy, not getting the last 2

Grab tokens only from lines containing a specific substring at unknown position within the first token

I have a log file that contains lines similar to:
1 3 2 4 5 6 4 3 2 4 6 6 53 54 5 5 7 4 35 52 234 234 423 26 6 2465 3
asdfj:C:kkl 4 5 6 5 4 3 2 3 4 5 6 7 6 5 45 6
1 3 2 4 5 6 4 3 2 4 6 6 53 54 5 5 7 4 35 52 234 234 423 26 6 2465 3
1 3 2 4 5 6 4 3 2 4 6 6 xdfj:C:asdfj 53 54 5 5 7 4 35 52 234 234 423 26 6 2465 3
jdfj:C:asdfj 4 5 6 5 4 3 2 3 4 5 6 7 6 5 789 6
asfgfj:C:asdfj 4 5 6 5 4 3 2 3 4 5 6 7 6 5 23 6
I need to grab the 1st and 16th tokens from all lines that BEGIN with strings containing the substring ":C:" (lines 2, 5, 6 in the example) and return these to an output file.
I'm using "FINDSTR" to grab these tokens, but I only know how to grab from all lines. How can I filter to grab from only lines beginning with the string/substring I want?
*Note: The substring ":C:" varies in it's position within the string, or else I would just try to match this ":C:" if it's position was constant.
Current commands I'm using:
#echo off
setlocal enabledelayedexpansion
for /F "tokens=1,16" %%a in (print.log) do (
echo %%a %%b >> value.txt)
This batch:
#Echo off
SetLocal EnableDelayedExpansion
for /F "tokens=1,16" %%a in (
' findstr /R /C:"^[^ ]*:C:" print.log'
) do echo %%a %%b >> value.txt
returns this output in value.txt:
> type value.txt
asdfj:C:kkl 45
jdfj:C:asdfj 789
asfgfj:C:asdfj 23

How to print the field with duplicate value in .txt file

I have a file like this
File
124 3 ac 7
143 3 zf 10
176 8 lm 1
547 7 km 5
862 8 sf 6
991 7 zv 6
I want to create 3 different files from this with following output
File 1
124 3 ac 7
143 3 zf 10
File 2
176 8 lm 1
862 8 sf 6
File 3
547 7 km 5
991 7 zv 6
Please help me with the commands.
$awk 'NR>1{print $2,$3,$4 > $1}' File
This command did the work for me.
Thank You!!

Resources