Postgresql 中文操作指南
45.7. PL/Perl Event Triggers #
可以使用 PL/Perl 编写事件触发器函数。在事件触发器函数中,哈希引用 $_TD 包含有关当前触发器事件的信息。$_TD 是全局变量,对于触发器的每次调用都会获取一个单独的本地值。$_TD 哈希引用的字段为:
PL/Perl can be used to write event trigger functions. In an event trigger function, the hash reference $_TD contains information about the current trigger event. $_TD is a global variable, which gets a separate local value for each invocation of the trigger. The fields of the $_TD hash reference are:
-
$_TD→{event}
-
The name of the event the trigger is fired for.
-
-
$_TD→{tag}
-
The command tag for which the trigger is fired.
-
将忽略触发器函数的返回值。
The return value of the trigger function is ignored.
以下是一个事件触发器函数示例,说明上述的部分内容:
Here is an example of an event trigger function, illustrating some of the above:
CREATE OR REPLACE FUNCTION perlsnitch() RETURNS event_trigger AS $$
elog(NOTICE, "perlsnitch: " . $_TD->{event} . " " . $_TD->{tag} . " ");
$$ LANGUAGE plperl;
CREATE EVENT TRIGGER perl_a_snitch
ON ddl_command_start
EXECUTE FUNCTION perlsnitch();