作为 FROM 的一部分提供 tsvector 以在 postgres 中进行全面搜索

Supplying tsvector for full search in postgres as part of FROM

我有一个如下所示的文本搜索查询

with query as (select to_tsquery('sometext'))
select
    t1.id
from 
    table1 as t1,
    to_tsvector(t1.f1) as vector
where
    (select * from query) @@ vector

这按预期工作。但是当我尝试像这样向向量添加更多字段时

with query as (select to_tsquery('sometext'))
select
    t1.id
from 
    table1 as t1,
    to_tsvector(t1.f1) || to_tsvector(t1.f2) as vector
where
    (select * from query) @@ vector

我在 || 附近收到语法错误。我在这里做错了什么?

我的数据库是 PostgreSQL 9.4。

允许 FROM 列表像 table 一样进行函数调用,但不允许使用运算符表达式。您可以将其转换为等效的函数调用:

with query as (select to_tsquery('sometext'))
select
    t1.id
from 
    table1 as t1,
    tsvector_concat(to_tsvector(t1.f1), to_tsvector(t1.f2)) as vector
where
    (select * from query) @@ vector