G'day folks,

Forgive this if it's totally "out there" but I was wondering why there's no
support for triggers on a TRUNCATE operation.  I note that a COPY IN fires
an INSERT trigger (if defined).

The only real use I can see for a TRUNCATE trigger would be for automatic
audit trail generation - I usually have all operations on "core" tables
audited.

FYI, I'm using 7.4.3.

As always, thanks for your time.  Ciao.

-- 
-------------------------------------------------------+---------------------
Daniel Baldoni BAppSc, PGradDipCompSci                 |  Technical Director
require 'std/disclaimer.pl'                            |  LcdS Pty. Ltd.
-------------------------------------------------------+  856B Canning Hwy
Phone/FAX:  +61-8-9364-8171                            |  Applecross
Mobile:     041-888-9794                               |  WA 6153
URL:        http://www.lcds.com.au/                    |  Australia
-------------------------------------------------------+---------------------
"Any time there's something so ridiculous that no rational systems programmer
 would even consider trying it, they send for me."; paraphrased from "King Of
 The Murgos" by David Eddings.  (I'm not good, just crazy)

Mon, 26 Jul 2004 16:27:08 +0800
Daniel Baldoni <pgsql@lcds.com.au>
Triggers on TRUNCATE?
Daniel Baldoni <pgsql@lcds.com.au> writes:
> Forgive this if it's totally "out there" but I was wondering why there's no
> support for triggers on a TRUNCATE operation.

Because the entire point of TRUNCATE is not to scan the table contents.

If you want to fire triggers, just use "DELETE FROM foo".

			regards, tom lane

Mon, 26 Jul 2004 10:59:06 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Triggers on TRUNCATE? 
On E, 2004-07-26 at 17:59, Tom Lane wrote:
> Daniel Baldoni <pgsql@lcds.com.au> writes:
> > Forgive this if it's totally "out there" but I was wondering why there's no
> > support for triggers on a TRUNCATE operation.
> 
> Because the entire point of TRUNCATE is not to scan the table contents.

Maybe he was after statement level triggers ?

We don't support them, and one also can't define a RULE for TRUNCATE -
so the advice would be to use TRUNCATE very sparingly ;)

Btw, does the right to TRUNCATE come with GRANT DELETE, or must one be a
superuser to TRUNCATE ?

---------------
Hannu


Tue, 27 Jul 2004 03:45:16 +0300
Hannu Krosing <hannu@tm.ee>
Re: Triggers on TRUNCATE?
Hannu Krosing <hannu@tm.ee> writes:
> Btw, does the right to TRUNCATE come with GRANT DELETE, or must one be a
> superuser to TRUNCATE ?

You have to own the table (or be superuser of course).  This implies the
right to drop its triggers, so TRUNCATE could be seen as dropping
triggers, DELETE, recreate triggers.

			regards, tom lane

Mon, 26 Jul 2004 22:50:05 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: Triggers on TRUNCATE? 