可能有其他的方法,但这里是一个:
SELECT ft.id, mw.words
FROM debug_fullText ft, lateral
(select array_agg(matchword) as words, count(*) as cnt
from debug_matchwords
where title ilike matchWord
) mw
where mw.cnt > 0;
这里是一个例子:
with debug_fulltext as (
select 1 as id, 'a b c'::text as title
),
debug_matchwords(matchword) as (
values ('%a%'::text), ('%b%')
)
select ft.id, mw.words
from debug_fullText ft, lateral
(select array_agg(matchword) as words, count(*) as cnt
from debug_matchwords
where title ilike matchWord
) mw
where mw.cnt > 0;
这将返回两个单词。
编辑II:
这将返回比赛对我来说:
with debug_fulltext as (
select 3893382135 as id, 'Tate Modern'::text as title
),
debug_matchwords(id, matchword) as (
values (1, 'Westminister'),
(2 , 'Tate Modern'),
(3 , 'South Afrika'),
(4 , 'London')
)
SELECT ft.id, mw.words
FROM debug_fullText ft, lateral
(select array_agg(matchword) as words, count(*) as cnt
from debug_matchwords
where title ilike matchWord
) mw
where mw.cnt > 0;
如果它不为你工作,那么有可能是字符集问题还是人品不好伪装,比如说,如空间。
感谢它的工作。 :) 当你说其他方法, 你的意思是可能有更快或不必要的其他方法! – Raha1986
但它不返回所有匹配的单词!它发现第一场比赛时停止! – Raha1986
@ Raha1986。 。 。这可能是您打印数组的方式。也许你应该使用'string_agg()'而不是'array_agg()'。 –