pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedtrigger : emulate "instead of" with before ?
4+ messages / 4 participants
[nested] [flat]
* trigger : emulate "instead of" with before ?
@ 2003-06-13 11:50 Albrecht Berger <berger1517@gmx.ch>
0 siblings, 3 replies; 4+ messages in thread
From: Albrecht Berger @ 2003-06-13 11:50 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: trigger : emulate "instead of" with before ?
@ 2003-06-13 13:09 Matthew Nuzum <cobalt@bearfruit.org>
parent: Albrecht Berger <berger1517@gmx.ch>
2 siblings, 0 replies; 4+ messages in thread
From: Matthew Nuzum @ 2003-06-13 13:09 UTC (permalink / raw)
To: 'Albrecht Berger' <berger1517@gmx.ch>; pgsql-sql
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: trigger : emulate "instead of" with before ?
@ 2003-06-13 13:50 Jeff Eckermann <jeff_eckermann@yahoo.com>
parent: Albrecht Berger <berger1517@gmx.ch>
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Eckermann @ 2003-06-13 13:50 UTC (permalink / raw)
To: Albrecht Berger <berger1517@gmx.ch>; pgsql-sql
I believe that if you return NULL from the trigger
function, the delete will not actually be done. You
could set the value of the delete flag by reference to
OLD.fieldname.
I have not actually done this myself, so caveat
emptor.
--- Albrecht Berger <berger1517@gmx.ch> wrote:
> 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
__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: trigger : emulate "instead of" with before ?
@ 2003-06-13 13:57 Tom Lane <tgl@sss.pgh.pa.us>
parent: Albrecht Berger <berger1517@gmx.ch>
2 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2003-06-13 13:57 UTC (permalink / raw)
To: Albrecht Berger <berger1517@gmx.ch>; +Cc: pgsql-sql
"Albrecht Berger" <berger1517@gmx.ch> writes:
> 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 ?
If the BEFORE DELETE trigger returns NULL, the delete is skipped.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-06-13 13:57 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-13 11:50 trigger : emulate "instead of" with before ? Albrecht Berger <berger1517@gmx.ch>
2003-06-13 13:09 ` Matthew Nuzum <cobalt@bearfruit.org>
2003-06-13 13:50 ` Jeff Eckermann <jeff_eckermann@yahoo.com>
2003-06-13 13:57 ` Tom Lane <tgl@sss.pgh.pa.us>
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