use a column as an input for to_tsquery

431 Views Asked by At

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');
1

There are 1 best solutions below

3
On BEST ANSWER

That would be a simple join between the tables:

SELECT t2.*
FROM t1 JOIN t2
   ON t2.tags = t1.word;

No need for full text search!