Postgresql pg_搜索和多列索引(Rails 4)

Postgresql pg_搜索和多列索引(Rails 4),postgresql,ruby-on-rails-4,indexing,pg-search,multiple-columns,Postgresql,Ruby On Rails 4,Indexing,Pg Search,Multiple Columns,我在PostgreSQL中有一个全文搜索查询,如下所示: to_tsvector('english', coalesce("products"."name"::text, '')) || to_tsvector('english', coalesce("products"."uid"::text, '')) || to_tsvector('english', coalesce("products"."serial"::text, '')); 但由于某些原因,创建这样的迁移不起作用: creat

我在PostgreSQL中有一个全文搜索查询,如下所示:

to_tsvector('english', coalesce("products"."name"::text, '')) || to_tsvector('english', coalesce("products"."uid"::text, '')) || to_tsvector('english', coalesce("products"."serial"::text, ''));
但由于某些原因,创建这样的迁移不起作用:

create_trigger(compatibility: 1).on(:products).before(:insert, :update) do
  "new.tsv_body := to_tsvector('english', coalesce("products"."name"::text, '')) || to_tsvector('english', coalesce("products"."uid"::text, '')) || to_tsvector('english', coalesce("products"."serial"::text, ''));"
end

有什么建议吗?

提示是堆栈溢出语法如何突出显示程序文本:

  "new.tsv_body := to_tsvector('english', coalesce("products"."name"::text, '')) .... )
                                                   ^^^^^^^^^^ ^^^^^^
在表名和列名周围包含了双引号。整个字符串用双引号括起来。因此,这些插入双引号结束字符串

你需要避开它们,或者忽略它们。我不使用Ruby/Rails,但如果它与大多数语言一样,反斜杠转义是合适的:

"new.tsv_body := to_tsvector('english', coalesce(\"products\".\"name\"::text, '')) .... )

每当你写“不起作用”时,这是一个标志,你需要删除这些词,并用它不起作用的实际描述取代它们。它做什么/不做什么?你预期会有什么影响?到底发生了什么?是否有任何错误消息或日志消息?请注意。这是一个可怕的问题。当我注释掉迁移运行的双引号时,下面的答案起作用了。然后,我尝试在控制台中运行:Product.find_each(&:touch)并得到以下错误:PG::UndefinedTable:error:missing FROM表“products”的子句条目听起来像是“new question”材料。有细节!