历史版本。 PostgreSQL 9.3 已结束支持。 2018-11-08. 请参阅 当前版本手册.
9.28. 事件触发器函数 #
目前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 章。