cube2222 / octosql

OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Mozilla Public License 2.0
4.78k stars 202 forks source link

Allow using multiple dots in file names without wrapping in backticks. #295

Open nbk2000 opened 2 years ago

nbk2000 commented 2 years ago

Using octosql version 0.9.4 and running the following command:

octosql "SELECT * FROM example.com.json"

Results in the following error:

Error: couldn't parse query: invalid argument syntax error at position 27

If the filename is changed to example_com.json then no error occurs and the program functions normally

cube2222 commented 2 years ago

@nbk2000 could you try wrapping it in back ticks?

SELECT * FROM `example.com.json`
nbk2000 commented 2 years ago

That results in the same error

cube2222 commented 2 years ago

@nbk2000 can't reproduce, I've just tried

octosql "SELECT * FROM `books.test.json`"

and it works perfectly well.

Is it possible that a different part of your query is resulting in that error?

nbk2000 commented 2 years ago

I don't think so, since changing the filename results in correct behavior, and the error message is quite explicit as to the position of the offending character. For example:

octosql "SELECT * FROM `example.com.json`"

results in the error:

Error: couldn't parse query: invalid argument syntax error at position 15

While removing the backticks like this:

octosql "SELECT * FROM example.com.json"

results in the error:

Error: couldn't parse query: invalid argument syntax error at position 27

This is on Ubuntu AMD64, in case that makes any difference.

Out of curiosity, What happens on your system when you don't include the back ticks?

cube2222 commented 2 years ago

Ok, this actually seems to be caused by bash. I've been running on the fish shell, but on bash I get the same error as you and the first line of the output is

bash: example.com.json: command not found

so it seems like bash is treating the backticked part like a command it should execute and use the output of.

Escaping it seems to work correctly:

octosql "SELECT * FROM \`example.com.json\`"
nbk2000 commented 2 years ago

Yep backticks cause execution in bash. My results are the same as yours, so this is a workable workaround.

Can I make a feature request that multi dot files be supported without resorting to escaped backticks? (seems like an unnecessary footgun)

cube2222 commented 2 years ago

Sure, agreed, I'll look into it when I have some time. Until then, I'll change the title of this issue to track this.

amotl commented 1 year ago

Hi there,

Escaping it seems to work correctly. Yep backticks cause execution in bash. My results are the same as yours, so this is a workable workaround.

I was struggling on the same thing and wanted to add that using single quotes is another option.

octosql 'SELECT * FROM `foo-bar.csv`;'

With kind regards, Andreas.

P.S.: By the way, thanks so much for conceiving octosql, @cube2222.