pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matthew Nuzum <cobalt@bearfruit.org>
To: 'Albrecht Berger' <berger1517@gmx.ch>
To: 'pgsql' <pgsql-sql@postgresql.org>
Subject: Re: trigger : emulate "instead of" with before ?
Date: Fri, 13 Jun 2003 09:09:52 -0400
Message-ID: <001501c331ad$14207300$a322fea9@mattspc> (raw)
In-Reply-To: <046801c331a2$0c483e70$a07ba8c0@wxp>

I'm not a postgres expert, and I certainly don't know the details of your
situation, but it seems to me you may want to use a rule instead of a
trigger.

Then, you can intercept the delete query and simply re-write it to be an
update query that sets your deleted flag.

--
Matthew Nuzum
www.bearfruit.org
cobalt@bearfruit.org
 
> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-
> owner@postgresql.org] On Behalf Of Albrecht Berger
> Sent: Friday, June 13, 2003 7:51 AM
> To: pgsql
> Subject: [SQL] trigger : emulate "instead of" with before ?
> 
> Hello,
> I need a trigger which is updating a delete flag of a row instead of
> deleting it physically.
> 
> How do I implement a trigger which doesn't execute a delete without
> raising
> an exception
> in plsql ?
> 
> CREATE TRIGGER trigger1 BEFORE DELETE ON table1
> FOR EACH ROW EXECUTE PROCEDURE setDeleteFlag ();
> 
> If I use
> RAISE EXCEPTION "..."
> the delete statement isn't executed, but I think the transaction is rolled
> back too, am I right ?
> 
> So what is the best way to implement something (Oracle like) like that :
> CREATE TRIGGER trigger1 INSTEAD OF DELETE ON table1
> FOR EACH ROW EXECUTE PROCEDURE setDeleteFlag ();
> 
> thx
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/docs/faqs/FAQ.html




view thread (4+ messages)  latest in thread

Message-ID: <001501c331ad$14207300$a322fea9@mattspc>
Permalink:  ../001501c331ad$14207300$a322fea9@mattspc/
Also on:    postgresql.org/message-id/001501c331ad$14207300$a322fea9@mattspc

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: cobalt@bearfruit.org, berger1517@gmx.ch
  Subject: Re: trigger : emulate "instead of" with before ?
  In-Reply-To: <001501c331ad$14207300$a322fea9@mattspc>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox