Postgresql:获取匹配的关键字

时间:2016-11-25 05:50:52

标签: postgresql

我需要在单独的列中从结果中获取匹配的关键字。

表:

| name    | description       | info            |  matched        |
|---------|-------------------|-----------------|-----------------|
| Event1  | This will be great| great experience|great,experience |
| Event2  | great experience  | great thinking  |great,experience |
| Event3  | Great match       | think           |great            |

阵列: {很大,经验}

使用这个数组我想要匹配的关键字,如上所示

1 个答案:

答案 0 :(得分:0)

这样的事情:

select e.name, 
       e.description,
       (select string_agg(distinct lower(m.word), ',') 
        from regexp_split_to_table(concat_ws(' ', e.description, e.info), '\s') as m(word) 
        where lower(m.word) = any(array['great','experience']))
from events e;

但那不会很快

在线示例:http://rextester.com/UHAU52066