Skip site navigation (1) Skip section navigation (2)

pgsql: Add sql_drop event for event triggers

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Add sql_drop event for event triggers
Date: 2013-03-28 16:08:30
Message-ID: E1ULFNO-0004x6-VI@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-hackers
Add sql_drop event for event triggers

This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command.  (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing).  Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire.  Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.

The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code.  This means that careful tracking of object
identification is required during the object removal phase.

Like other currently existing events, there is support for tag
filtering.

To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command.  This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.

Catalog version bumped due to the new function.

Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/473ab40c8bb3fcb1a7645f6a7443a0424d70fbaf

Modified Files
--------------
doc/src/sgml/event-trigger.sgml             |  110 ++++++-
doc/src/sgml/func.sgml                      |  113 ++++++
src/backend/catalog/dependency.c            |   65 +++-
src/backend/commands/event_trigger.c        |  518 +++++++++++++++++++++++----
src/backend/parser/gram.y                   |    1 -
src/backend/tcop/utility.c                  |   64 +++-
src/backend/utils/adt/regproc.c             |    2 +-
src/backend/utils/cache/evtcache.c          |    2 +
src/include/catalog/catversion.h            |    2 +-
src/include/catalog/pg_proc.h               |    3 +
src/include/commands/event_trigger.h        |    9 +-
src/include/utils/builtins.h                |    3 +
src/include/utils/evtcache.h                |    3 +-
src/test/regress/expected/event_trigger.out |  197 ++++++++++-
src/test/regress/sql/event_trigger.sql      |  106 ++++++-
15 files changed, 1083 insertions(+), 115 deletions(-)


Responses

pgsql-hackers by date

Next:From: Alvaro HerreraDate: 2013-03-28 16:13:40
Subject: Re: sql_drop Event Triggerg
Previous:From: Tom LaneDate: 2013-03-28 15:54:59
Subject: Re: FDW for PostgreSQL

pgsql-committers by date

Next:From: Tom LaneDate: 2013-03-28 17:19:56
Subject: pgsql: Avoid "variable might be clobbered by longjmp" warning.
Previous:From: Simon RiggsDate: 2013-03-28 15:07:08
Subject: Re: [COMMITTERS] pgsql: Allow external recovery_config_directory

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group