2016-11-25 84 views
0

我需要從單獨列中的結果中獲取匹配的關鍵字。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   | 

陣: {很大,經驗}

隨着這陣我想匹配的關鍵字如上圖

回答

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