我在触发器上创建评论:
COMMENT ON TRIGGER my_trigger on my_table IS $$comment on trigger$$;
然后检索这样的评论:
select description
from pg_description
join pg_trigger on pg_description.objoid = pg_trigger.tgfoid
where tgname = 'my_trigger';
但声明返回0行。
这是表及其触发器:
=# \d ps_dbupdates
Column | Type | Modifiers
--------+---------+-----------------------------------------------------------
id | integer | not null default nextval('ps_dbupdates_id_seq'::regclass)
update | integer | not null
Indexes:
"ps_dbupdates_pkey" PRIMARY KEY, btree (id)
Triggers:
single_dbupdate_trigger BEFORE INSERT ON ps_dbupdates FOR EACH ROW EXECUTE PROCEDURE single_dbupdate()
我对声明的评论:
=# COMMENT ON TRIGGER single_dbupdate_trigger ON ps_dbupdates IS $$ensure there is only one row in table ps_dbupdates$$;
获取触发器的oid:
=# select tgrelid, tgname, tgfoid from pg_trigger where tgname='single_dbupdate_trigger';
tgrelid | tgname | tgfoid
---------+-------------------------+--------
16689 | single_dbupdate_trigger | 16590
(1 row)
使用obj_description(object_oid,catalog_name)来检索注释:
=# select obj_description(16590,'pg_trigger');
obj_description
-----------------
(1 row)
最后一点,PostgreSQL版本:
$ psql --version
psql (PostgreSQL) 8.4.21
答案 0 :(得分:0)
根据文档,有预制功能可以回复你的评论。
http://www.postgresql.org/docs/9.3/static/functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE
此信息可通过以下答案找到:How to retrieve the comment of a PostgreSQL database?
答案 1 :(得分:0)
select description
from pg_description
join pg_trigger on pg_description.objoid = pg_trigger.oid
where tgname = 'my_trigger';
我犯的错误是我在join语句中给出了错误的触发器oid。 oid列未显示在“\ d pg_trigger”或pg_trigger的postgresql文档中。因此,postgresql中的基本原则是不显示列'oid'。
select obj_description(oid, 'pg_trigger')
只要给出正确的oid,也应该有效;