pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。
目前PostgreSQL提供一个内建的事件触发器辅助函数,即pg_event_trigger_dropped_objects。
pg_event_trigger_dropped_objects返回在命令的sql_drop事件中调用它时该命令删除的所有对象的列表。如果在其他任何上下文中调用,pg_event_trigger_dropped_objects会报错。pg_event_trigger_dropped_objects返回下面的列:
| 名称 | 类型 | 描述 |
|---|---|---|
classid |
Oid |
对象所属系统目录的 OID |
objid |
Oid |
对象在目录中的 OID |
objsubid |
int32 |
子对象 ID(例如列的属性编号) |
object_type |
text |
对象的类型 |
schema_name |
text |
对象所属模式的名称(若有);否则为NULL。不加引号。 |
object_name |
text |
对象的名称(如果该类型没有名称,则为NULL)。不加引号。 |
object_identity |
text |
对象标识的文本呈现,带模式限定。标识中的每个标识符在必要时都会加引号。 |
pg_event_trigger_dropped_objects函数可以这样用于一个事件触发器:
CREATE FUNCTION test_event_trigger_for_drops()
RETURNS event_trigger LANGUAGE plpgsql AS $$
DECLARE
obj record;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
LOOP
RAISE NOTICE '% dropped object: % %.% %',
tg_tag,
obj.object_type,
obj.schema_name,
obj.object_name,
obj.object_identity;
END LOOP;
END
$$;
CREATE EVENT TRIGGER test_event_trigger_for_drops
ON sql_drop
EXECUTE PROCEDURE test_event_trigger_for_drops();
更多有关事件触发器的信息,请参见第 37 章。
译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。