Book Image

PostgreSQL Server Programming - Second Edition

Book Image

PostgreSQL Server Programming - Second Edition

Overview of this book

Table of Contents (21 chapters)
PostgreSQL Server Programming Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating event triggers


Event triggers are created using the CREATE EVENT TRIGGER command. Before you can create an event trigger, you need a function that the trigger will execute. This function must return a special type called EVENT_TRIGGER. If you happen to define multiple event triggers, they are executed in the alphabetical order of their names.

Currently, event triggers are supported on three events, as follows:

  • ddl_command_start: This event occurs just before a CREATE, ALTER, or DROP DDL command is executed

  • ddl_command_end: This event occurs just after a CREATE, ALTER, or DROP command has finished executing

  • sql_drop: This event occurs just before the ddl_command_end event for the commands that drop database objects

You can specify a WHEN clause with the CREATE EVENT TRIGGER command, so that the event is fired only for the specified commands.

The event trigger PL/pgSQL functions have access to the following new variables introduced in 9.3:

  • TG_TAG: This variable contains the "tag" or the...