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

46.5. トリガ関数 #

<title>Trigger Functions</title>

When a function is used as a trigger, the dictionary <literal>TD</literal> contains trigger-related values: トリガとして関数を使用した場合、TD辞書にトリガに関連した値が格納されます。

TD["event"]

contains the event as a string: <literal>INSERT</literal>, <literal>UPDATE</literal>, <literal>DELETE</literal>, or <literal>TRUNCATE</literal>. 次のイベントが文字列として格納されます。 INSERTUPDATEDELETETRUNCATE

TD["when"]

contains one of <literal>BEFORE</literal>, <literal>AFTER</literal>, or <literal>INSTEAD OF</literal>. BEFOREAFTER、またはINSTEAD OFのいずれかが格納されます。

TD["level"]

contains <literal>ROW</literal> or <literal>STATEMENT</literal>. ROWまたはSTATEMENTが格納されます。

TD["new"]
TD["old"]

For a row-level trigger, one or both of these fields contain the respective trigger rows, depending on the trigger event. 行レベルトリガにおいてトリガイベントに依存して、これらのフィールドの片方または両方に対応するトリガ行が格納されます。

TD["name"]

contains the trigger name. トリガ名が格納されます。

TD["table_name"]

contains the name of the table on which the trigger occurred. トリガの発生元のテーブルの名前が格納されます。

TD["table_schema"]

contains the schema of the table on which the trigger occurred. トリガの発生元のテーブルのスキーマが格納されます。

TD["relid"]

contains the OID of the table on which the trigger occurred. トリガの発生元テーブルのOIDが格納されます。

TD["args"]

If the <command>CREATE TRIGGER</command> command included arguments, they are available in <literal>TD["args"][0]</literal> to <literal>TD["args"][<replaceable>n</replaceable>-1]</literal>. CREATE TRIGGERに引数が含まれていた場合、その引数はTD["args"][0]からTD["args"][n-1]までの範囲で使用することができます。

If <literal>TD["when"]</literal> is <literal>BEFORE</literal> or <literal>INSTEAD OF</literal> and <literal>TD["level"]</literal> is <literal>ROW</literal>, you can return <literal>None</literal> or <literal>"OK"</literal> from the Python function to indicate the row is unmodified, <literal>"SKIP"</literal> to abort the event, or if <literal>TD["event"]</literal> is <command>INSERT</command> or <command>UPDATE</command> you can return <literal>"MODIFY"</literal> to indicate you've modified the new row. Otherwise the return value is ignored. TD["when"]BEFOREまたはINSTEAD OFで、かつ、TD["level"]ROWの場合、Pythonの関数から、行が変更されないことを示すNoneまたは"OK"、イベントを中断したことを示す"SKIP"を返すことができます。 また、TD["event"]INSERTまたはUPDATEの場合、行を変更したことを示す"MODIFY"を返すことができます。 さもなければ、戻り値は無視されます。