From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Michael Nolan" <htfoot(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Returning NEW in an on-delete trigger |
Date: | 2008-09-18 19:04:43 |
Message-ID: | 25194.1221764683@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"Michael Nolan" <htfoot(at)gmail(dot)com> writes:
> Recently I discovered a coding error of mine in a trigger that is called
> only for deletes.
> I was returning NEW instead of OLD.
> Since NEW is undefined when deleting a row, it was failing and the row
> wasn't being deleted.
> However, it was failing silently. Shouldn't this have recorded an error or
> warning somewhere?
The NEW variable is just set up as being NULL in an ON DELETE trigger,
likewise for OLD in an ON INSERT trigger.
This does seem like a bit of a gotcha for someone who writes RETURN NEW
instead of RETURN OLD or vice versa, but I'm not sure how much we can do
about that. Lots of people like to write triggers that fire on multiple
event types, so we couldn't throw a syntax error for such a reference.
A runtime error for a use of the variable might be possible, but a quick
look at the code doesn't make it look easy.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2008-09-18 19:35:29 | Re: Running initdb while logged in as Administrator user (Windows) |
Previous Message | Jeff Davis | 2008-09-18 19:00:32 | Re: Returning NEW in an on-delete trigger |