I have a table T1
with only one column having 2000 unique words. There is another table T2
with a column of a word. I want to find the records in T2
were their words matches with one of the words in T1
.
So imagine T1
looks as following:
word
------
regents
sky
tree
trees
avenue
and T2
is like this:
tags | id| usrid
--------+----+--------
shifs | 1| @1
trees | 2| @2
sky | 3| @3
regents | 4| @4
regent | 5| @5
and I want to get results as follow:
tags | id| usrid
--------+----+--------
trees | 2| @2
sky | 3| @3
regents | 5| @5
I could use the below query to search the tags column from T2
but I want to use the word
column from T1
as an input for tsquery
.
SELECT *
FROM T2
WHERE to_tsvector(tags) @@ to_tsquery('regent');
That would be a simple join between the tables:
No need for full text search!