Postgresql 将字符串列与其他表中的列进行匹配
在Postgres中,如何将字符串与其他表中的列进行匹配?对于表IPostgresql 将字符串列与其他表中的列进行匹配,postgresql,full-text-search,psql,tsvector,Postgresql,Full Text Search,Psql,Tsvector,在Postgres中,如何将字符串与其他表中的列进行匹配?对于表Istring列中的每一行,搜索表II和表III中的所有行以查找匹配项,并将它们串联返回 我的目标是从字符串输入中派生匹配词和匹配结构 表一:字符串 string | match_words | match_structures --------------------------------------------------- Hi, my name is dan | | 表二:
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\uuuuuuuuuuuuuiis首先必须使用子字符串 您需要取表1并除以字符串行的每个值 在字符串数组中 第二个是对表2进行同样的操作 第三是比较你的表格 您需要使用两个循环来验证数组1和数组2的每个位置