在不同的表列上触发 Postgres 触发器

发布于 2024-08-28 17:35:41 字数 808 浏览 0 评论 0原文

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 添加到表 SEA​​RCH_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离 2024-09-04 17:35:41

默认的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文