Postgresql 中文操作指南
44.7. Event Trigger Functions in PL/Tcl #
事件触发器函数可以使用 PL/Tcl 编写。PostgreSQL 要求将被用作事件触发器的函数声明为无参数且返回类型 event_trigger 的函数。
Event trigger functions can be written in PL/Tcl. PostgreSQL requires that a function that is to be called as an event trigger must be declared as a function with no arguments and a return type of event_trigger.
触发器管理器的信息通过以下变量传递到函数主体:
The information from the trigger manager is passed to the function body in the following variables:
-
$TG_event
-
The name of the event the trigger is fired for.
-
-
$TG_tag
-
The command tag for which the trigger is fired.
-
将忽略触发器函数的返回值。
The return value of the trigger function is ignored.
以下是一个简单的示例事件触发器函数,它将在每次执行支持的命令时引发 NOTICE 消息:
Here’s a little example event trigger function that simply raises a NOTICE message each time a supported command is executed:
CREATE OR REPLACE FUNCTION tclsnitch() RETURNS event_trigger AS $$
elog NOTICE "tclsnitch: $TG_event $TG_tag"
$$ LANGUAGE pltcl;
CREATE EVENT TRIGGER tcl_a_snitch ON ddl_command_start EXECUTE FUNCTION tclsnitch();