Re: feature proposal - triggers by semantics

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Hannu Krosing <hannu(at)2ndquadrant(dot)com>
Cc: Craig Ringer <craig(at)2ndquadrant(dot)com>, Darren Duncan <darren(at)darrenduncan(dot)net>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: feature proposal - triggers by semantics
Date: 2012-11-16 04:25:31
Message-ID: CA+U5nMJKB=pJadWbiqazFM2k6GL7=a4g_vabyf0iO7RPLLZtrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 15 November 2012 05:25, Hannu Krosing <hannu(at)2ndquadrant(dot)com> wrote:
> On 11/15/2012 09:48 AM, Craig Ringer wrote:
>>
>> If you want to prevent TRUNCATE, deny the privilege or add a trigger
>> that aborts the command.
>
> You can abort the transaction but not skip action as currently it is only
> possible to skip in ROW level triggers.
>
> So I'd modify this request to allow BEFORE EACH STATEMENT triggers
> to also be able to silently skip current action like BEFORE EACH ROW
> triggers can.

+1

> Then this request would simply be satisfied by a simple trigger which
> rewrites TRUNCATE into DELETE .

However, we don't need to do that to make this work.

Just create a BEFORE EACH STATEMENT trigger on TRUNCATE that issues a
DELETE from table.
Then have a EACH ROW trigger on DELETE.

That way each row gets logged.

The TRUNCATE still occurs, but semantically does nothing, though
physically deletes the space used by the already deleted rows.

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2012-11-16 04:34:47 Re: logical changeset generation v3
Previous Message Pavan Deolasee 2012-11-16 04:14:49 Re: Do we need so many hint bits?