在不同的表列上触发 Postgres 触发器
CONTENT_TABLE
id | author | timestamp | title | description
----+-----------------+-----------+----------------+----------------------
(0 rows)
SEARCH_TABLE
id | content_type_id | object_id | tsvector_title | tsvector_description
----+-----------------+-----------+----------------+----------------------
(0 rows)
当 CONTENT_TABLE 更新/插入时,我必须触发触发器,
如下所示:
"CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON course_course FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(SHOULD_BE_THE_COLUMN_OF_SEARCH_TABLE(tsvector_description), 'pg_catalog.english', description);"
- 实际上,我必须将 CONTENT_TABLE 的标题和描述的 tsvector 添加到表 SEARCH_TABLE tsvector_title 和 tsvector_description 中。我可以只触发一个触发器吗?
任何形式的帮助将不胜感激。提前致谢。
CONTENT_TABLE
id | author | timestamp | title | description
----+-----------------+-----------+----------------+----------------------
(0 rows)
SEARCH_TABLE
id | content_type_id | object_id | tsvector_title | tsvector_description
----+-----------------+-----------+----------------+----------------------
(0 rows)
I have to fire a trigger when ever CONTENT_TABLE is UPDATED/INSERTED
Something like this:
"CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON course_course FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(SHOULD_BE_THE_COLUMN_OF_SEARCH_TABLE(tsvector_description), 'pg_catalog.english', description);"
- Actually, i have to add tsvector for title and description of the CONTENT_TABLE to the table SEARCH_TABLE tsvector_title and tsvector_description. Can i just fire one trigger for it?
Any sort of help will be appreciated. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认的 tsvector_update_trigger 不能查看另一个表。但如果您自己编写(例如 pl/pgsql),则可以轻松做到这一点。请参阅http://www.postgresql.org/docs/8.4/static /plpgsql-trigger.html。您只需收集数据并让函数调用 to_tsvector(),将结果粘贴到 tsvector 列中。
The default tsvector_update_trigger can't look at another table. But if you write your own (in for example pl/pgsql), you can do that easily. see http://www.postgresql.org/docs/8.4/static/plpgsql-trigger.html. You just need to collect your data and have your function call to_tsvector(), sticking the result in the tsvector column.