【发布时间】:2018-10-11 04:18:27
【问题描述】:
在 Postgres 中,如何将字符串与其他表中的列进行匹配?对于表 I string 列中的每一行,在表 II 和表 III 中的所有行中搜索匹配项并返回它们 / 连接。
我的目标是从字符串输入中导出匹配词和匹配结构。
表一:字符串
string | match_words | match_structures
---------------------------------------------------
Hi, my name is dan | |
表二:单词
word
----------
hello
hi
bird
name
表三:结构
structure
----------
hi, my name is
hello, my
how are you?
my is
所需的输出:表一:字符串
string | match_words | match_structures
---------------------------------------------------
Hi, my name is dan | hi/name | hi, my name is/my is
尝试:
使用 iLike:我得到了第一个匹配 hi,但不是所有子字符串都匹配:
update dialog set match_words = word from words where string ilike '%' || word || '%';
给我
string | match_words | match_structures
---------------------------------------------------
Hi, my name is dan | hi |
进行选择,我可以将完整的字符串与单个单词配对,我猜这与我想要的相反:
select string, word, structure from dialog left join words on (string ilike '%' || word || '%') left join structures on (string ilike '%' || structure || '%');
string | word | structure
--------------------+------+----------------
Hi, my name is dan | hi | hi, my name is
Hi, my name is dan | name | hi, my name is
这仍然缺少my ____ is的结构
【问题讨论】:
标签: postgresql full-text-search psql tsvector