简体   繁体   English

更新tsvector更新触发器

[英]Update tsvector update trigger

I have the following tsvector update trigger for a tsvector column 'user_tsv' on a table that allows me to perform full text searches, 我在表上允许我执行全文搜索的tsvector列'user_tsv'有以下tsvector更新触发器,

CREATE TRIGGER tsvector_user_update BEFORE INSERT OR UPDATE ON users
FOR EACH ROW EXECUTE PROCEDURE 
tsvector_update_trigger(user_tsv, 'pg_catalog.english', firstname, surname, email);
CREATE INDEX user_index_tsv ON users USING gin(user_tsv);

I have since added another column to the table that I want to include in this trigger, is there any way to update the trigger (and also the tsvector column) or do I need to drop the column / trigger and re-add them? 我已经在表中添加了另一个列,我希望包含在此触发器中,是否有任何方法可以更新触发器(以及tsvector列)或者是否需要删除列/触发器并重新添加它们?

PostgreSQL 9.0 PostgreSQL 9.0

Thanks in advance 提前致谢

David 大卫

You don't need to drop the column or the index, just drop and re-create the trigger and update any changed fields. 您不需要删除列或索引,只需删除并重新创建触发器并更新任何更改的字段。

Drop the trigger with a regular DROP TRIGGER statement, then re-create it with the new column using tsvector_update_trigger , all in the same transaction. 使用常规DROP TRIGGER语句DROP TRIGGER ,然后使用tsvector_update_trigger使用新列重新创建它,所有这些都在同一事务中。 Now UPDATE tablename SET user_tsv = ... WHERE new_column IS NOT NULL to update the column if you've already added columns. 现在UPDATE tablename SET user_tsv = ... WHERE new_column IS NOT NULL ,如果您已经添加了列,则更新列。 Examine the sources for the tsvector update trigger to find out the appropriate expression to use in the assignment. 检查tsvector更新触发器的源以找出要在分配中使用的适当表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM