[英]Text case-insitive search with crate.io SQL
What is the proper SQL syntax to search an array text in the crate database
? 在crate database
搜索数组文本的正确SQL语法是什么?
My example table is: 我的示例表是:
create table
tasks(user string, entry array(object as (taskid string, eTime timestamp))).
I tried the following which give a syntax error: 我尝试了以下语法错误:
select * from program where any(entry['taskid']) ~* '.*cleanup.*';
The correct syntax for the ANY operator would be: ANY运算符的正确语法为:
SELECT * FROM tasks WHERE '.*cleanup.*' ~* ANY(entry['taskid']);
However, PCRE
are currently not supported in combination with ANY
. 但是,目前不支持将PCRE
与ANY
结合使用。 An alternative would be the LIKE
predicate, but that is not case-insensitive (and can be quite slow if it starts with a wildcard character); 另一种可能是LIKE
谓词,但是它不区分大小写(如果以通配符开头,则可能会非常慢)。
So ultimately, you could ... 所以最终,您可以...
... either use a fulltext index on the entry['taskid']
column with a lowercase
analyzer (which is probably not the best solution, because I assume taskid
is a single word and you want to use it "as is" also), ...或者使用lowercase
分析器在entry['taskid']
列上使用全文索引 (这可能不是最佳解决方案,因为我假设taskid
是一个单词,并且您也想按原样使用它) ,
... or split up the array values into separate rows so you have a schema like: ...或将数组值拆分为单独的行,因此您将具有以下架构:
CREATE TABLE tasks (
user string,
entry OBJECT AS (
taskid STRING,
etime TIMESTAMP
)
) ...
The you can use 您可以使用
SELECT * FROM tasks WHERE entry['taskid'] ~* '.*cleanup.*';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.