バージョンごとのドキュメント一覧

44.7. PL/Tclにおけるイベントトリガ関数 #

<title>Event Trigger Functions in PL/Tcl</title>

Event trigger functions can be written in PL/Tcl. <productname>PostgreSQL</productname> 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 <literal>event_trigger</literal>. イベントトリガ関数をPL/Tclで作成することができます。 PostgreSQLでは、イベントトリガとして呼び出される関数は、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. トリガ関数の戻り値は無視されます。

Here's a little example event trigger function that simply raises a <literal>NOTICE</literal> message each time a supported command is executed: サポートするコマンドが実行される度に、単にNOTICEメッセージを発行するイベントトリガ関数の例を、以下に示します。

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();