Re: trigger for TRUNCATE? - Mailing list pgsql-sql

From Tom Lane
Subject Re: trigger for TRUNCATE?
Date
Msg-id 8003.1199986734@sss.pgh.pa.us
Whole thread Raw
In response to Re: trigger for TRUNCATE?  (Alvaro Herrera <alvherre@commandprompt.com>)
Responses Re: trigger for TRUNCATE?
Re: trigger for TRUNCATE?
List pgsql-sql
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Gerardo Herzig escribi�:
>> Yes, the TRUNCATE statement is not sql ansi, maybe is a more low level 
>> thing than i think.

> TRUNCATE currently does not fire triggers, but that doesn't mean it's
> impossible to do it.  I think it would be fairly easy to add support
> for that.

The entire point of TRUNCATE is to not do a table scan, so making it
fire per-row triggers seems pretty misguided to me.

We could maybe make it fire per-statement ON DELETE triggers, but
there's a future-proofing pitfall in that: someday it'd be nice
for statement-level triggers to have access to the set of deleted rows,
and then you'd be stuck either scanning the table or having TRUNCATE
act differently from plain DELETE.

My feeling is that if you want to know what was deleted, you shouldn't
use TRUNCATE.
        regards, tom lane


pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: trigger for TRUNCATE?
Next
From: Alvaro Herrera
Date:
Subject: Re: trigger for TRUNCATE?