{
    "mode": "man",
    "parameter": "CREATE_EVENT_TRIGGER",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/CREATE_EVENT_TRIGGER/7/json",
    "generated": "2026-07-05T10:46:34Z",
    "synopsis": "CREATE EVENT TRIGGER name\nON event\n[ WHEN filtervariable IN (filtervalue [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } functionname()",
    "sections": {
        "NAME": {
            "content": "CREATEEVENTTRIGGER - define a new event trigger\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "CREATE EVENT TRIGGER name\nON event\n[ WHEN filtervariable IN (filtervalue [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } functionname()\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CREATE EVENT TRIGGER creates a new event trigger. Whenever the designated event occurs and\nthe WHEN condition associated with the trigger, if any, is satisfied, the trigger function\nwill be executed. For a general introduction to event triggers, see Chapter 40. The user who\ncreates an event trigger becomes its owner.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "name\nThe name to give the new trigger. This name must be unique within the database.\n\nevent\nThe name of the event that triggers a call to the given function. See Section 40.1 for\nmore information on event names.\n\nfiltervariable\nThe name of a variable used to filter events. This makes it possible to restrict the\nfiring of the trigger to a subset of the cases in which it is supported. Currently the\nonly supported filtervariable is TAG.\n\nfiltervalue\nA list of values for the associated filtervariable for which the trigger should fire.\nFor TAG, this means a list of command tags (e.g., 'DROP FUNCTION').\n\nfunctionname\nA user-supplied function that is declared as taking no argument and returning type\neventtrigger.\n\nIn the syntax of CREATE EVENT TRIGGER, the keywords FUNCTION and PROCEDURE are\nequivalent, but the referenced function must in any case be a function, not a procedure.\nThe use of the keyword PROCEDURE here is historical and deprecated.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Only superusers can create event triggers.\n\nEvent triggers are disabled in single-user mode (see postgres(1)). If an erroneous event\ntrigger disables the database so much that you can't even drop the trigger, restart in\nsingle-user mode and you'll be able to do that.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Forbid the execution of any DDL command:\n\nCREATE OR REPLACE FUNCTION abortanycommand()\nRETURNS eventtrigger\nLANGUAGE plpgsql\nAS $$\nBEGIN\nRAISE EXCEPTION 'command % is disabled', tgtag;\nEND;\n$$;\n\nCREATE EVENT TRIGGER abortddl ON ddlcommandstart\nEXECUTE FUNCTION abortanycommand();\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "There is no CREATE EVENT TRIGGER statement in the SQL standard.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ALTER EVENT TRIGGER (ALTEREVENTTRIGGER(7)), DROP EVENT TRIGGER (DROPEVENTTRIGGER(7)),\nCREATE FUNCTION (CREATEFUNCTION(7))\n\n\n\nPostgreSQL 14.23                                2026                         CREATE EVENT TRIGGER(7)",
            "subsections": []
        }
    },
    "summary": "CREATEEVENTTRIGGER - define a new event trigger",
    "flags": [],
    "examples": [
        "Forbid the execution of any DDL command:",
        "CREATE OR REPLACE FUNCTION abortanycommand()",
        "RETURNS eventtrigger",
        "LANGUAGE plpgsql",
        "AS $$",
        "BEGIN",
        "RAISE EXCEPTION 'command % is disabled', tgtag;",
        "END;",
        "$$;",
        "CREATE EVENT TRIGGER abortddl ON ddlcommandstart",
        "EXECUTE FUNCTION abortanycommand();"
    ],
    "see_also": [
        {
            "name": "ALTEREVENTTRIGGER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/ALTEREVENTTRIGGER/7/json"
        },
        {
            "name": "DROPEVENTTRIGGER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/DROPEVENTTRIGGER/7/json"
        },
        {
            "name": "CREATEFUNCTION",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CREATEFUNCTION/7/json"
        },
        {
            "name": "TRIGGER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/TRIGGER/7/json"
        }
    ]
}