mithrandie / csvq

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

Single character comparison problem #11

Closed KandaAkihiro closed 5 years ago

KandaAkihiro commented 5 years ago

csvq is a useful tool. I am very grateful to csvq. But I can not solve the following problem.

Because of the behavior of Relational Operators, comparison of single character ('1', 'T' or '0', 'F') does not work well.

In the table (sample.txt) below.

flg,value
0,value1
F,value2
K,value3

I do this query.

csvq  "select * from sample where flg<>'F'"

The result does not contain "flg ='0'".

+-----+---------+
| flg |  value  |
+-----+---------+
| K   | value3  |
+-----+---------+

Is there any solution or workaround?

mithrandie commented 5 years ago

@KandaAkihiro

Come to think of it, that comparison does not return the expected result.

As a workaround, csvq supports the relational operator '==', though it is an operator not defined in the standard SQL. This operator checks not only whether the values are equivalent but also whether the types are the same.

https://mithrandie.github.io/csvq/reference/comparison-operators.html#relational_operators

The following query will return the expected result.

SELECT * FROM sample WHERE NOT flg == 'F';
KandaAkihiro commented 5 years ago

Of course "Not" is available. Sorry for bothering you.