How to simplify a query in PostgreSQL?

There is a query of the form:

 ts_rank_cd(to_tsvector('English', name), query)
FROM catalog_product,
 to_tsquery('russian', 'TV') query
WHERE to_tsvector('English', name) @@ query;

It confuses me that there is a duplication of a part of the "to_tsvector('English', name)".
Actually this is a simplified example, in the real query there in this place much more complicated than something like
setweight( coalesce( to_tsvector('English', name),"),'A') || '' || 
setweight( coalesce( to_tsvector('russian', array_to_string(items, ' ')),"),'B')

Copy-paste a puttee twice does not want.

If there was a simple table, it would be possible to add a field to a table with the counted vector. In my case this cannot be done, because I choose not from the table, and another query where scounty many tables.

You can do without copy-paste?
June 26th 19 at 14:06
0 answer

Find more questions by tags PostgreSQL