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

CREATE EVENT TRIGGER

CREATE EVENT TRIGGER <refpurpose>define a new event trigger</refpurpose> — 新しいイベントトリガを定義する

概要

CREATE EVENT TRIGGER name
    ON event
    [ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
    EXECUTE { FUNCTION | PROCEDURE } function_name()

説明

<title>Description</title>

<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条件がもしあればそれを満たす場合、トリガ関数が実行されます。 イベントトリガの一般的な紹介については、第40章を参照してください。 イベントトリガを作成したユーザがその所有者となります。

パラメータ

<title>Parameters</title>
name

The name to give the new trigger. This name must be unique within the database. 新しいトリガに付ける名前です。 この名前はデータベース内で一意でなければなりません。

event

The name of the event that triggers a call to the given function. See <xref linkend="event-trigger-definition"/> for more information on event names. 指定関数を呼び出すきっかけとなるイベントの名前です。 イベント名の詳細については40.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の構文では、キーワードFUNCTIONPROCEDUREは等価ですが、参照されている関数はどちらの場合でも関数でなければならず、プロシージャであってはなりません。 ここでキーワードPROCEDUREを使うことは、歴史的なものであり廃止予定です。

注釈

<title>Notes</title>

Only superusers can create event triggers. スーパーユーザのみがイベントトリガを作成することができます。

Event triggers are disabled in single-user mode (see <xref linkend="app-postgres"/>). If an erroneous event trigger disables the database so much that you can't even drop the trigger, restart in single-user mode and you'll be able to do that. シングルユーザモード(postgres参照)ではイベントトリガは無効になります。 エラーのあるイベントトリガが原因でデータベースの動作がおかしくなり、トリガを削除することもできない状態になった場合は、シングルユーザモードで再起動してください。 削除できるようになります。

<title>Examples</title>

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

互換性

<title>Compatibility</title>

There is no <command>CREATE EVENT TRIGGER</command> statement in the SQL standard. 標準SQLにはCREATE EVENT TRIGGER文はありません。

関連項目

<title>See Also</title> ALTER EVENT TRIGGER, DROP EVENT TRIGGER, CREATE FUNCTION