Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELECT '' is NULL rather than empty string #49

Closed
derekmahar opened this issue Mar 21, 2021 · 8 comments
Closed

SELECT '' is NULL rather than empty string #49

derekmahar opened this issue Mar 21, 2021 · 8 comments

Comments

@derekmahar
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

What is the dual table?

mithrandie added a commit that referenced this issue Mar 21, 2021
- Fix a bug of dual table. ([GitHub #49](#49))
@mithrandie
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Owner

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

@derekmahar
Copy link
Contributor Author

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
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants