Re: Delete rule does not prevent truncate

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Tim Smith <randomdev4+postgres(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Delete rule does not prevent truncate
Date: 2015-07-22 13:03:33
Message-ID: CANu8FiyWW_5BimnyZLkrDNcq2z-Jxt5+isBzSwnXpay77tnk=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Actually, if you use a TRIGGER instead of rule, you can handle this.
The manual states event can be:

INSERT
UPDATE [ OF column_name [, ... ] ]
DELETE*TRUNCATE <-----*

http://www.postgresql.org/docs/9.4/interactive/sql-createtrigger.html

I suggest you review carefully.

On Wed, Jul 22, 2015 at 8:53 AM, Tim Smith <randomdev4+postgres(at)gmail(dot)com>
wrote:

> Hi,
>
> I very much hope this is an accidental bug rather than a deliberate
> feature !
>
> PostgreSQL 9.4.4
>
> create rule no_auditupd as on update to app_security.app_audit do
> instead nothing;
> create rule no_auditdel as on delete to app_security.app_audit do
> instead nothing;
>
> \d+ app_security.app_audit
> <snip>
> Rules:
> no_auditdel AS
> ON DELETE TO app_security.app_audit DO INSTEAD NOTHING
> no_auditupd AS
> ON UPDATE TO app_security.app_audit DO INSTEAD NOTHING
>
> The truncate trashes the whole table ;-(
>
> According to the FabulousManual(TM) :
> event : The event is one of SELECT, INSERT, UPDATE, or DELETE.
>
> Thus I can't create a rule to "do nothing" on truncates, thus I am stuck !
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tim Smith 2015-07-22 13:13:35 Re: Delete rule does not prevent truncate
Previous Message Tim Smith 2015-07-22 12:53:22 Delete rule does not prevent truncate