to_tsquery - Does it always accept quert text?
If the values can be arbitrary strings, you can get errors:
SELECT to_tsquery('a&amp;');
ERROR:  no operand in tsquery: &quot;a&amp;&quot;
SELECT to_tsquery('''q');
ERROR:  syntax error in tsquery: &quot;'q&quot;

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