I am very new to FTS features in Postgres, in fact, have started exploring them since yesterday only.

I wanted to pass list of values stored in columns of a DB tables instead of query text in to_tsquery.

Something like this:

select  * 
from t1
 where to_tsvector("col1") @@ to_tsquery((select col2 from t2 where id = 123))

Not sure if this is a possibility? Is there any alternative by which such kind of implementation can be achieved using to_tsquery?


1 Answer 1


If the values can be arbitrary strings, you can get errors:

SELECT to_tsquery('a&');
ERROR:  no operand in tsquery: "a&"
SELECT to_tsquery('''q');
ERROR:  syntax error in tsquery: "'q"

Use plainto_tsquery, which is designed to accept plain text strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.