CREATE_EVENT_TRIGGER(7pg14)
πΈ NAME πΈ
CREATE_EVENT_TRIGGER β define a new event trigger. π
okay bestie, this is the CREATE_EVENT_TRIGGER(7pg14) page from the PostgreSQL 14.24 documentation. Itβs literally here to help you define a new event trigger β and yes, itβs giving very much βautomate the dramaβ energy. β¨
β¨ 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. Whenever the designated event occurs and the WHEN condition associated with the trigger β if any β is satisfied, the trigger function will be executed. fr fr, thatβs the whole point. π₯
For a general introduction to event triggers, see Chapter 40. The user who creates an event trigger becomes its owner. main character ownership moment β¨
π PARAMETERS π
nameβ the name youβre giving the new trigger. It must be unique within the database. no duplicate names, bestie πeventβ the name of the event that triggers a call to the given function. See Section 40.1 for more information 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. iykyk β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. π«Ά
π¦ NOTES π¦
- Only superusers can create event triggers. no cap. π
- Event triggers are disabled in single-user mode (see
postgres(1)). 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. rescue-mode arc π
π 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();
iconic. periodt. π β¨
β COMPATIBILITY β
There is no CREATE EVENT TRIGGER statement in the SQL standard. the SQL standard is literally not giving this one π
π SEE ALSO π
- ALTER EVENT TRIGGER (
ALTER_EVENT_TRIGGER(7)) π¦ - DROP EVENT TRIGGER (
DROP_EVENT_TRIGGER(7)) π - CREATE FUNCTION (
CREATE_FUNCTION(7)) πΈ
xoxo, your PostgreSQL 14.24 docs bestie, dated 2026 β now go slay those triggers π β¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-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