harelba / q

q - Run SQL directly on delimited files and multi-file sqlite databases

Home Page:http://harelba.github.io/q/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

unphased opened this issue · comments

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.

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

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

Thank you for the clarification!