CREATE EVENT TRIGGER <refpurpose>define a new event trigger</refpurpose> — 新しいイベントトリガを定義する
CREATE EVENT TRIGGERnameONevent[ WHENfilter_variableIN (filter_value[, ... ]) [ AND ... ] ] EXECUTE { FUNCTION | PROCEDURE }function_name()
<command>CREATE EVENT TRIGGER</command> creates a new event trigger.
Whenever the designated event occurs and the <literal>WHEN</literal> condition
associated with the trigger, if any, is satisfied, the trigger function
will be executed. For a general introduction to event triggers, see
<xref linkend="event-triggers"/>. The user who creates an event trigger
becomes its owner.
CREATE EVENT TRIGGERは新しいイベントトリガを作成します。
指定されたイベントが発生し、トリガに関連するWHEN条件がもしあればそれを満たす場合、トリガ関数が実行されます。
イベントトリガの一般的な紹介については、第38章を参照してください。
イベントトリガを作成したユーザがその所有者となります。
nameThe name to give the new trigger. This name must be unique within the database. 新しいトリガに付ける名前です。 この名前はデータベース内で一意でなければなりません。
eventThe name of the event that triggers a call to the given function. See <xref linkend="event-trigger-definition"/> for more information on event names. 指定関数を呼び出すきっかけとなるイベントの名前です。 イベント名の詳細については38.1を参照してください。
filter_variable
The name of a variable used to filter events. This makes it possible
to restrict the firing of the trigger to a subset of the cases in which
it is supported. Currently the only supported
<replaceable class="parameter">filter_variable</replaceable>
is <literal>TAG</literal>.
イベントをフィルタするために使用される変数の名前です。
これにより、サポートしている状況の一部に対してのみにトリガの発行を制限することができます。
現在filter_variableでサポートされているものはTAGのみです。
filter_value
A list of values for the
associated <replaceable class="parameter">filter_variable</replaceable>
for which the trigger should fire. For <literal>TAG</literal>, this means a
list of command tags (e.g., <literal>'DROP FUNCTION'</literal>).
どこでトリガを発行すべきかについて、関連するfilter_variable用の値のリストです。
TAGの場合、これはコマンドタグ(例えば'DROP FUNCTION')のリストを意味します。
function_name
A user-supplied function that is declared as taking no argument and
returning type <literal>event_trigger</literal>.
引数を取らずevent_trigger型を返すと宣言された、ユーザが提供する関数です。
In the syntax of <literal>CREATE EVENT TRIGGER</literal>, the keywords
<literal>FUNCTION</literal> and <literal>PROCEDURE</literal> are
equivalent, but the referenced function must in any case be a function,
not a procedure. The use of the keyword <literal>PROCEDURE</literal>
here is historical and deprecated.
CREATE EVENT TRIGGERの構文では、キーワードFUNCTIONとPROCEDUREは等価ですが、参照されている関数はどちらの場合でも関数でなければならず、プロシージャであってはなりません。
ここでキーワードPROCEDUREを使うことは、歴史的なものであり廃止予定です。
Only superusers can create event triggers. スーパーユーザのみがイベントトリガを作成することができます。
Event triggers are disabled in single-user mode (see <xref
linkend="app-postgres"/>) as well as when
<xref linkend="guc-event-triggers"/> is set to <literal>false</literal>.
If an erroneous event trigger disables the database so much that you can't
even drop the trigger, restart with <xref linkend="guc-event-triggers"/>
set to <literal>false</literal> to temporarily disable event triggers, or
in single-user mode, and you'll be able to do that.
event_triggersがfalseに設定されている場合と同じように、シングルユーザモード(postgres参照)ではイベントトリガは無効になります。
エラーのあるイベントトリガが原因でデータベースの動作がおかしくなり、トリガを削除することもできない状態になった場合は、一時的にイベントトリガを無効にするためにevent_triggersをfalseに設定して再起動するか、シングルユーザモードで再起動してください。そうすれば削除できるようになります。
Forbid the execution of any <link linkend="ddl">DDL</link> command: すべてのDDLコマンドの実行を禁じます。
CREATE OR REPLACE FUNCTION abort_any_command() RETURNS event_trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION 'command % is disabled', tg_tag; END; $$; CREATE EVENT TRIGGER abort_ddl ON ddl_command_start EXECUTE FUNCTION abort_any_command();
There is no <command>CREATE EVENT TRIGGER</command> statement in the
SQL standard.
標準SQLにはCREATE EVENT TRIGGER文はありません。