From: | Jan Wieck <JanWieck(at)Yahoo(dot)com> |
---|---|
To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: AFTER triggers & RETURN |
Date: | 2009-11-20 03:28:11 |
Message-ID: | 4B060CCB.4010809@Yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 11/5/2009 8:10 PM, Robert Haas wrote:
> On Thu, Nov 5, 2009 at 4:57 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>>> Robert Haas wrote:
>>>> Since the return value is ignored anyway, why do we have to complain
>>>> if it's left out altogether? Granted, it's easy to work around, but
>>>> still.
>>
>>> Isn't is a requirement of plpgsql that you not fall off the end of a
>>> function unless it is declared to return void? The function doesn't know
>>> if it will be called before or after.
>>
>> Yeah, it couldn't be done as a compile-time check. You could probably
>> make it work if you converted the error to a run-time test. Not sure
>> if that's really an improvement though.
>
> Well, as it is, you don't get an error when you define the function,
> only when you do something that causes it to be invoked. An error
> when you define the function would probably be a small improvement,
> because at least it would be obvious that you'd broke something (and
> the transaction that tried to break it would roll back). No error at
> all seems better still.
>
> Perhaps in an ideal world before and after trigger functions would
> have different signatures - like the before trigger should perhaps
> take two rows as arguments and return a row, and the after trigger
> should take two rows as arguments and return void. The idea of
> overloading the function's return type to provide it with special,
> magical input parameters is pretty funky and means that you can't
> invoke that function in any context other than as a trigger, which
> would occasionally be useful. I think we're stuck with it at this
> point, but maybe it's possible to at least relax the requirement to
> explicitly return a useless result.
One could of course have triggers return NEW by default for invocations
on INSERT or UPDATE, and OLD on DELETE. That would make the default
behavior of BEFORE triggers to let the original operation through and
fix the annoyance.
Jan
--
Anyone who trades liberty for security deserves neither
liberty nor security. -- Benjamin Franklin
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2009-11-20 03:35:23 | Re: Why do OLD and NEW have special internal names? |
Previous Message | Andrew Dunstan | 2009-11-20 02:58:40 | Re: Summary and Plan for Hot Standby |