使用 crate.io SQL 进行文本区分大小写搜索
Text case-insitive search with crate.io SQL
在 crate database
中搜索数组文本的正确 SQL 语法是什么?
我的例子table是:
create table
tasks(user string, entry array(object as (taskid string, eTime timestamp))).
我尝试了以下给出语法错误的方法:
select * from program where any(entry['taskid']) ~* '.*cleanup.*';
ANY operator 的正确语法是:
SELECT * FROM tasks WHERE '.*cleanup.*' ~* ANY(entry['taskid']);
但是,PCRE
目前不支持与 ANY
结合使用。另一种选择是 LIKE
谓词,但它不区分大小写(如果它以通配符开头,速度可能会很慢);
所以最终,你可以...
...要么使用 fulltext index on the entry['taskid']
column with a lowercase
analyzer(这可能不是最好的解决方案,因为我假设 taskid
是一个单词,而你也想使用它 "as is") ,
... 或将数组值拆分为单独的行,这样您就有了如下架构:
CREATE TABLE tasks (
user string,
entry OBJECT AS (
taskid STRING,
etime TIMESTAMP
)
) ...
你可以使用
SELECT * FROM tasks WHERE entry['taskid'] ~* '.*cleanup.*';
在 crate database
中搜索数组文本的正确 SQL 语法是什么?
我的例子table是:
create table
tasks(user string, entry array(object as (taskid string, eTime timestamp))).
我尝试了以下给出语法错误的方法:
select * from program where any(entry['taskid']) ~* '.*cleanup.*';
ANY operator 的正确语法是:
SELECT * FROM tasks WHERE '.*cleanup.*' ~* ANY(entry['taskid']);
但是,PCRE
目前不支持与 ANY
结合使用。另一种选择是 LIKE
谓词,但它不区分大小写(如果它以通配符开头,速度可能会很慢);
所以最终,你可以...
...要么使用 fulltext index on the entry['taskid']
column with a lowercase
analyzer(这可能不是最好的解决方案,因为我假设 taskid
是一个单词,而你也想使用它 "as is") ,
... 或将数组值拆分为单独的行,这样您就有了如下架构:
CREATE TABLE tasks (
user string,
entry OBJECT AS (
taskid STRING,
etime TIMESTAMP
)
) ...
你可以使用
SELECT * FROM tasks WHERE entry['taskid'] ~* '.*cleanup.*';