在 Postgres 中,如何将字符串与其他表中的列进行匹配?对于表 Istring
列中的每一行,在表 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
期望的输出:表 I:字符串
string | match_words | match_structures
---------------------------------------------------
Hi, my name is dan | hi/name | hi, my name is/my is
尝试:
使用 iLike: 我得到了第一个 match 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