CREATE_EVENT_TRIGGER(7)
💖 CREATE EVENT TRIGGER(7) 💖
okay bestie, so we're deep in the PostgreSQL 18.6 Documentation and this page is literally about CREATE EVENT TRIGGER — define a new event trigger. yes, the big-girl version of triggers. pull up a chair 🎀
✨ NAME ✨
CREATE_EVENT_TRIGGER — define a new event trigger 👑
✨ SYNOPSIS ✨
CREATE EVENT TRIGGER name
ON event
[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
EXECUTE { FUNCTION | PROCEDURE } function_name()
✨ DESCRIPTION ✨
so basically, CREATE EVENT TRIGGER makes a brand new event trigger. whenever the event you picked happens, and the WHEN condition attached to the trigger (if there even is one) is satisfied, the trigger function runs. simple as that. 💅
for the full general intro to event triggers, go look at Chapter 38.
and the glow-up detail: whoever creates an event trigger becomes its owner. main character energy fr fr 🫶
✨ PARAMETERS ✨
name— the name you're giving your new trigger. it has to be unique within the database, no duplicates, we don't do that here. 🚫event— the name of the event that fires a call to the function. head to Section 38.1 for the deets on event names. 📖filter_variable— the name of a variable used to filter events. this is the part that lets you restrict the trigger so it only fires for a subset of the cases where it's supported. currently the only supportedfilter_variableisTAG. that's it. that's the whole list. 💀filter_value— a list of values for the associatedfilter_variablethat you want the trigger to fire for. forTAG, this means a list of command tags (like, for example,'DROP FUNCTION'). 🏷️function_name— a user-supplied function that's declared as taking no argument and returning typeevent_trigger.
okay important side note: in the syntax ofCREATE EVENT TRIGGER, the keywordsFUNCTIONandPROCEDUREare equivalent, BUT the thing you reference has to be a function in any case, not a procedure. thePROCEDUREkeyword here is historical and deprecated. so like… don't, bestie. 🙈
✨ NOTES ✨
only superusers can create event triggers. that's the vibe check. 👑
event triggers are disabled in single-user mode (see postgres(1)), and also disabled whenever event_triggers is set to false.
and listen, if some erroneous event trigger breaks your database SO badly that you can't even drop the trigger? 😭 restart withevent_triggersset tofalseto temporarily disable event triggers, or go in via single-user mode — and then you'll be able to drop it. you're welcome. 🫶
✨ EXAMPLES ✨
want to forbid the execution of any DDL command? slay, here you go:
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. not a thing. we're built different. 🌈
✨ SEE ALSO ✨
ALTER EVENT TRIGGER(ALTER_EVENT_TRIGGER(7))DROP EVENT TRIGGER(DROP_EVENT_TRIGGER(7))CREATE FUNCTION(CREATE_FUNCTION(7))
and that's the whole page, bestie 💜 this was PostgreSQL 18.6, dated 2026, page CREATE EVENT TRIGGER(7) — go forth and trigger responsibly, mwah 🎀✨🦋
📦 where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 · PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 · PostgreSQL
- arch rolling: postgresql 18.6-4 · PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 · PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 · PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 · PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 · PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 · PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 · PostgreSQL
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms