When concatenating tsvectors from setweight in an SQL query, it throws a syntax error:
ERROR: syntax error at or near "||"
It works fine if I try it with a single tsvector returned by setweight
, and if I try to wrap the entire thing in another to_tsvector
call, it errors with the reason that there is no to_tsvector(tsvector)
function, so the concatenation is indeed forming a tsvector.
SELECT *, ts_rank_cd(textsearch, query) AS score
FROM products, plainto_tsquery('awesome shirt') query,
setweight(to_tsvector(coalesce(title, '')), 'A') ||
setweight(to_tsvector(coalesce(description, '')), 'B') ||
setweight(to_tsvector(coalesce(tags, '')), 'C') ||
setweight(to_tsvector(coalesce(vendor, '')), 'D') textsearch
WHERE shop_url='somedomain.com' AND query @@ textsearch
ORDER BY score DESC
LIMIT 20 OFFSET 0;
I've tried wrapping it in a subquery, but that makes it a record, which causes issues with ts_rank_cd
, since it's expecting textsearch
to be of type tsvector. How can I get this concatented tsvector to work in this query?