简体   繁体   中英

Text case-insitive search with crate.io SQL

What is the proper SQL syntax to search an array text in the crate database ?

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:

SELECT * FROM tasks WHERE '.*cleanup.*' ~* ANY(entry['taskid']);

However, PCRE are currently not supported in combination with 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);

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),

... 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.*';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM