Truncate Triggers - Mailing list pgsql-hackers

From Simon Riggs
Subject Truncate Triggers
Date
Msg-id 1201261219.4257.437.camel@ebony.site
Whole thread Raw
Responses Re: Truncate Triggers
Re: Truncate Triggers
Re: Truncate Triggers
List pgsql-hackers
(for 8.4 ...)
I'd like to introduce triggers that fire when we issue a truncate:

CREATE TRIGGER name [BEFORE | AFTER ] TRUNCATE ON table
FOR EACH STATEMENT EXECUTE PROCEDURE function (arguments);

The truncate trigger would fire separately from a statement-level DELETE
statement, to allow us to distinguish those two events. There would be
nothing to stop both triggers executing the same function however, if
desired.

COPY already provides a model for how a utility command can execute
triggers. tablecmds.c would invoke ExecBSTruncateTriggers() and
ExecASTruncateTriggers(), both of which would live in triggers.c

There doesn't seem much too difficult about the implementation or
behaviour, but I want to make sure we have the discussion at least, to
see if anybody has concerns or additional requirements.

Notes: As the syntax shows, these would be statement-level triggers
(only). Requesting row level triggers will cause an error. [As Chris
Browne explained, if people really want, they can use these facilities
to create a Before Statement trigger that executes a DELETE, which then
fires row level calls.]

I also plan to add a TRUNCATE privilege, though that will be a separate
patch in a later post. That will widen the use case of TRUNCATE, which
should be OK to do once we've covered the replication concerns.

--  Simon Riggs 2ndQuadrant  http://www.2ndQuadrant.com



pgsql-hackers by date:

Previous
From: Florian Weimer
Date:
Subject: plperl: Documentation on BYTEA decoding is wrong
Next
From: Peter Eisentraut
Date:
Subject: Default index tablespace