harelba / q

q - Run SQL directly on delimited files and multi-file sqlite databases
http://harelba.github.io/q/
GNU General Public License v3.0
10.19k stars 421 forks source link

Can't get character groups (`[]`) to work #289

Closed unphased closed 2 years ago

unphased commented 2 years ago

Here's an example:

echo $'1,fE+2,a\n2,2E+2,b' | q -d, 'select * from - where c2 like "%[2]E+2"'

That doesn't work, I can't get any [] to work, even when escaped with a backslash. It's not clear if this is simply a missing feature or what.

bitti commented 2 years ago

I suppose you're confusing pattern matching via like with regexp matching? The SQLite like operator only supports the % and _ wildcards and has nothing to do with regexp (e.g. see https://www.sqlitetutorial.net/sqlite-like/). However if the regexp extension is active, you can use the regexp operator. E.g. this is working for me:

$ echo $'1,fE+2,a\n2,2E+2,b' | q -d, 'select * from - where c2 regexp "[2]E\+2"'
2,2E+2,b
harelba commented 2 years ago

thanks @bitti for the answer. Indeed the regexp syntax can be used for such a use-case.

unphased commented 2 years ago

Thank you for the clarification!