'\" t .\" Title: CREATE EVENT TRIGGER .\" Author: The PostgreSQL Global Development Group .\" Generator: DocBook XSL Stylesheets v1.75.2 .\" Date: 2016 .\" Manual: PostgreSQL 9.5.2 Documentation .\" Source: PostgreSQL 9.5.2 .\" Language: English .\" .TH "CREATE EVENT TRIGGER" "5sql" "2016" "PostgreSQL 9.5.2" "PostgreSQL 9.5.2 Documentation" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" CREATE_EVENT_TRIGGER \- define a new event trigger .SH "SYNOPSIS" .sp .nf CREATE EVENT TRIGGER \fIname\fR ON \fIevent\fR [ WHEN \fIfilter_variable\fR IN (filter_value [, \&.\&.\&. ]) [ AND \&.\&.\&. ] ] EXECUTE PROCEDURE \fIfunction_name\fR() .fi .SH "DESCRIPTION" .PP \fBCREATE EVENT TRIGGER\fR 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\&. For a general introduction to event triggers, see Chapter 37, Event Triggers, in the documentation\&. The user who creates an event trigger becomes its owner\&. .SH "PARAMETERS" .PP \fIname\fR .RS 4 The name to give the new trigger\&. This name must be unique within the database\&. .RE .PP \fIevent\fR .RS 4 The name of the event that triggers a call to the given function\&. See Section 37.1, \(lqOverview of Event Trigger Behavior\(rq, in the documentation for more information on event names\&. .RE .PP \fIfilter_variable\fR .RS 4 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 supported \fIfilter_variable\fR is TAG\&. .RE .PP \fIfilter_value\fR .RS 4 A list of values for the associated \fIfilter_variable\fR for which the trigger should fire\&. For TAG, this means a list of command tags (e\&.g\&. \(aqDROP FUNCTION\(aq)\&. .RE .PP \fIfunction_name\fR .RS 4 A user\-supplied function that is declared as taking no argument and returning type event_trigger\&. .RE .SH "NOTES" .PP Only superusers can create event triggers\&. .PP Event triggers are disabled in single\-user mode (see \fBpostgres\fR(1))\&. If an erroneous event trigger disables the database so much that you can\(aqt even drop the trigger, restart in single\-user mode and you\(aqll be able to do that\&. .SH "EXAMPLES" .PP Forbid the execution of any DDL command: .sp .if n \{\ .RS 4 .\} .nf CREATE OR REPLACE FUNCTION abort_any_command() RETURNS event_trigger LANGUAGE plpgsql AS $$ BEGIN RAISE EXCEPTION \(aqcommand % is disabled\(aq, tg_tag; END; $$; CREATE EVENT TRIGGER abort_ddl ON ddl_command_start EXECUTE PROCEDURE abort_any_command(); .fi .if n \{\ .RE .\} .SH "COMPATIBILITY" .PP There is no \fBCREATE EVENT TRIGGER\fR statement in the SQL standard\&. .SH "SEE ALSO" ALTER EVENT TRIGGER (\fBALTER_EVENT_TRIGGER\fR(5)), DROP EVENT TRIGGER (\fBDROP_EVENT_TRIGGER\fR(5)), CREATE FUNCTION (\fBCREATE_FUNCTION\fR(5))