CREATE_EVENT_TRIGGER(7pg17)
okay bestie, welcome to the CREATE EVENT TRIGGER(7) page from the PostgreSQL 17.11 docs π this one's giving "make a trigger that fires on events" and it's honestly iconic β¨
πΈ NAME πΈ
CREATE_EVENT_TRIGGER β defines a brand-new event trigger, periodt π
π¦ SYNOPSIS π¦
CREATE EVENT TRIGGER name
ON event
[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
EXECUTE { FUNCTION | PROCEDURE } function_name()
β¨ DESCRIPTION β¨
CREATE EVENT TRIGGER creates a new event trigger, no cap. Whenever the designated event happens, and the WHEN condition associated with the trigger β if there is one β is satisfied, the trigger function gets executed π₯
For a general introduction to event triggers, see Chapter 38. And listen: the user who creates an event trigger becomes its owner π
π PARAMETERS π
nameβ the name you're giving the new trigger. This name must be unique within the database, so no duplicate-name drama πeventβ the name of the event that triggers a call to the given function. See Section 38.1 for more info on event names π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 supportedfilter_variableisTAGπ·οΈfilter_valueβ a list of values for the associatedfilter_variablefor which the trigger should fire. ForTAG, this means a list of command tags (e.g.,'DROP FUNCTION') π¬function_nameβ a user-supplied function that is declared as taking no argument and returning typeevent_trigger.
In the syntax of CREATE EVENT TRIGGER, the keywords FUNCTION and PROCEDURE are equivalent, but the referenced function must in any case be a function, not a procedure. The use of the keyword PROCEDURE here is historical and deprecated β so yeah, it's giving old-school, not main character energy π
π NOTES π
Only superusers can create event triggers. That's the rule, bestie π¨
Event triggers are disabled in single-user mode (see postgres(1)) as well as when event_triggers is set to false. If an erroneous event trigger disables the database so much that you can't even drop the trigger, restart with event_triggers set to false to temporarily disable event triggers, or in single-user mode, and you'll be able to do that π«Ά
okay but fr fr, if your trigger nuked the vibe that hard, this is the emergency exit π use it.
π EXAMPLES π
Forbid the execution of any DDL command:
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();
π§ COMPATIBILITY π§
There is no CREATE EVENT TRIGGER statement in the SQL standard. It's simply not on the standard's radar, bestie π
π SEE ALSO π
ALTER EVENT TRIGGER(ALTER_EVENT_TRIGGER(7))DROP EVENT TRIGGER(DROP_EVENT_TRIGGER(7))CREATE FUNCTION(CREATE_FUNCTION(7))
byeee bestie π this page is from PostgreSQL 17.11, dated 2026 β CREATE EVENT TRIGGER(7) out π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms