mithrandie / csvq

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

SELECT '' is NULL rather than empty string #49

Closed derekmahar closed 3 years ago

derekmahar commented 3 years ago

Why does SELECT '' result in NULL rather than ''?

$ csvq "SELECT '' AS col1"
+------+
| col1 |
+------+
| NULL |
+------+

For comparison, in both MySQL 5.7 and PostgreSQL 13, SELECT '' produces ''.

mithrandie commented 3 years ago

In csvq, when the dual table is used, an empty string matches the column name in the dual table, so the value of that column in the dual table, null, is displayed as the value of the column whose column name is the empty string.

This behavior is probably rarely a problem, but it might need to be fixed.

derekmahar commented 3 years ago

What is the dual table?

mithrandie commented 3 years ago

The dual table is a table prepared by DBMSs that is used to retrieve pseudo columns. It has one column and one record, so you can get the result you want by processing it like any other SELECT queues.

SELECT 1; is an abbreviated syntax of SELECT 1 FROM DUAL;.

derekmahar commented 3 years ago

Does the null value in the dual table column having empty string as its name also apply if you assign the column a name?

mithrandie commented 3 years ago

I'm not sure I understand your intention, but if you want to give an alias to the column name in the dual table, that operation is not available.

mithrandie commented 3 years ago

This bug has been fixed and the fix is included in the version 1.14.1.

derekmahar commented 3 years ago

I'm not sure I understand your intention, but if you want to give an alias to the column name in the dual table, that operation is not available.

Didn't I assign an alias to the column name in my original example?

derekmahar commented 3 years ago

This bug has been fixed and the fix is included in the version 1.14.1.

I verified that this issue is fixed in version 1.14.1:

$ csvq "SELECT '' AS col1"
+------+
| col1 |
+------+
|      |
+------+
$ csvq --version
csvq version 1.14.1

Thank you!