가 다른 방법 일 수 있지만, 여기에 하나입니다 수 있습니다
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. . . 아마 배열을 인쇄하는 방법 일 것입니다. 아마도'array_agg()'대신에'string_agg()'를 사용해야 할 것입니다. –