mithrandie / csvq

SQL-like query language for csv
https://mithrandie.github.io/csvq
MIT License
1.5k stars 65 forks source link

Select Query Error - (Where Clause) ; syntax error: unexpected token ">=" #32

Closed Cardosaum closed 4 years ago

Cardosaum commented 4 years ago

Hello all!

I just discovered this tool and was poking around with it. Seams like some queries were not yet implemented?

Say I have this input file:

$ cat input.txt
count,string
77766,in the
73529,for the
56800,of the
48059,on the
46528,to be
43250,to the
41130,thanks for
36993,at the
34185,i love
34015,going to

If I try to select only those rows with count greater or equal to 56800, I get this error:

$ cat input.txt | csvq -f csv "SELECT * FROM stdin WHERE count >= 56800"
[L:1 C:33] syntax error: unexpected token ">="

However, if I just grab everything, I do get the rows:

$ cat input.txt | csvq -f csv "SELECT * FROM stdin"
count,string
77766,in the
73529,for the
56800,of the
48059,on the
46528,to be
43250,to the
41130,thanks for
36993,at the
34185,i love
34015,going to

am I doing something wrong or it's just the case that this sort of queries were not yet implemented?

ondohotola commented 4 years ago

Count is a reserved word, so maybe try count ?

el

— Sent from Dr Lisse’s iPad Mini 5 On 16 Aug 2020, 18:39 +0200, Matheus Cardoso notifications@github.com, wrote:

Hello all! I just discovered this tool and was poking around with it. Seams like some queries were not yet implemented? Say I have this input file: $ cat input.txt count,string 77766,in the 73529,for the 56800,of the 48059,on the 46528,to be 43250,to the 41130,thanks for 36993,at the 34185,i love 34015,going to If I try to select only those rows with count greater or equal to 56800, I get this error: $ cat input.txt | csvq -f csv "SELECT FROM stdin WHERE count >= 56800" [L:1 C:33] syntax error: unexpected token ">=" However, if I just grab everything, I do get the rows: $ cat input.txt | csvq -f csv "SELECT FROM stdin" count,string 77766,in the 73529,for the 56800,of the 48059,on the 46528,to be 43250,to the 41130,thanks for 36993,at the 34185,i love 34015,going to am I doing something wrong or it's just the case that this sort of queries were not yet implemented? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

mithrandie commented 4 years ago

As @ondohotola said, you can execute the following commands.

$ cat input.txt | csvq -f csv 'SELECT * FROM stdin WHERE `count` >= 56800'
$ cat input.txt | csvq -f csv –ansi-quotes 'SELECT * FROM stdin WHERE "count" >= 56800'

Reserved Words https://mithrandie.github.io/csvq/reference/statement.html#reserved_words Grammar of identifier https://mithrandie.github.io/csvq/reference/statement.html#parsing

Cardosaum commented 4 years ago

Oh, I should had read the documentation more carefully.

Thanks for the quick response, and great project!