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

Allow using double-quotes for escaping. #303

Closed
codekitchen opened this issue Oct 16, 2022 · 3 comments
Closed

Allow using double-quotes for escaping. #303

codekitchen opened this issue Oct 16, 2022 · 3 comments

Comments

@codekitchen
Copy link

I have a csv file that has a column named key, which seems to be a reserved word in octosql? select key from myfile.csv errors with

Error: couldn't parse query: invalid argument syntax error at position 11 near 'key'

I tried escaping the identifier with double-quotes following the SQL standard, but that seems to actually create a string literal in octosql, same as with single-quotes?

❯ octosql 'select "key" from myfile.csv limit 3'
+-------+
| col_0 |
+-------+
| 'key' |
| 'key' |
| 'key' |
+-------+

I also tried brackets (select [key] from) but that errors as well. Is there a way to escape identifiers that I am missing in the docs? Thanks!

@cube2222
Copy link
Owner

Hey @codekitchen!

You can escape keywords (and also complex file paths) using backticks. So in this case that would be:

SELECT `key` FROM myfile.csv

However, keep in mind that if you're using bash, you need to escape backticks, so the above becomes:

octosql 'SELECT \`key\` FROM myfile.csv'

That said, using double quotes for escaping is a good idea (following the SQL standard, as you said). Thanks for it! It would also partially solve #295.

I'll update the issue title to track adding this (changing from the current behaviour of treating double-quotes as string literals).

@cube2222 cube2222 changed the title cannot escape reserved words / identifiers Allow using double-quotes for escaping. Oct 16, 2022
@codekitchen
Copy link
Author

aha, thank you. and 👍 on allowing double-quotes as is standard.

one note: escaping the backticks isn't necessary in bash (and zsh) if you wrap the whole query in single-quotes, e.g. this works fine:

octosql 'select `key` from myfile.csv'

but if wrapping in double-quotes, you do need to escape the backticks:

octosql "select \`key\` from myfile.csv"

@cube2222
Copy link
Owner

cube2222 commented Oct 20, 2022

@codekitchen FYI double quotes for literals have been released as part of v0.12.0.

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