Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
CREATE EVENT TRIGGER
Prev UpSQL CommandsHome Next

CREATE EVENT TRIGGER

CREATE EVENT TRIGGER — define a new event trigger

Synopsis

CREATE EVENT TRIGGERname    ONevent    [ WHENfilter_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 theWHEN condition associated with the trigger, if any, is satisfied, the trigger function will be executed. For a general introduction to event triggers, seeChapter 38. The user who creates an event trigger becomes its owner.

Parameters

name

The name to give the new trigger. This name must be unique within the database.

event

The name of the event that triggers a call to the given function. SeeSection 38.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_variable isTAG.

filter_value

A list of values for the associatedfilter_variable for 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 ofCREATE EVENT TRIGGER, the keywordsFUNCTION andPROCEDURE are equivalent, but the referenced function must in any case be a function, not a procedure. The use of the keywordPROCEDURE here is historical and deprecated.

Notes#

Only superusers can create event triggers.

Event triggers are disabled in single-user mode (seepostgres) as well as whenevent_triggers is set tofalse. If an erroneous event trigger disables the database so much that you can't even drop the trigger, restart withevent_triggers set tofalse to temporarily disable event triggers, or in single-user mode, and you'll be able to do that.

Examples#

Forbid the execution of anyDDL 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 noCREATE EVENT TRIGGER statement in the SQL standard.


Prev Up Next
CREATE DOMAIN Home CREATE EXTENSION
pdfepub
Go to Postgres Pro Standard 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp