Truncate Triggers

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Truncate Triggers
Date: 2008-01-25 11:40:19
Message-ID: 1201261219.4257.437.camel@ebony.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2008-01-25 11:40:24 Re: REINDEX on large DB vs. DROP INDEX/CREATE INDEX
Previous Message Florian Weimer 2008-01-25 10:50:41 plperl: Documentation on BYTEA decoding is wrong