Re: Rules: passing new/old to functions - Mailing list pgsql-sql

From Tom Lane
Subject Re: Rules: passing new/old to functions
Date
Msg-id 24557.1056685762@sss.pgh.pa.us
Whole thread Raw
In response to Rules: passing new/old to functions  (Gunter Diehl <gdid@gmx.de>)
List pgsql-sql
Gunter Diehl <gdid@gmx.de> writes:
> create funtion f1(v, v) returns void as '...'
> create rule vupt as on update to v do instead select f1(new, old)
> While accepting this definitions, pg says it can not handle "whole-tuple
> references" at runtime.

FWIW, the "old" case works fine.  "new" doesn't work so well because the
new row hasn't been formed into a tuple at the point where the rule
runs; it only exists as a list of variables.  (This is a rather handwavy
explanation, but I think it captures the key point.)  While this could
probably be fixed with some effort, I doubt it's going to happen soon.
Is there any chance of doing what you want with a trigger instead of a
rule?
        regards, tom lane


pgsql-sql by date:

Previous
From: Ian Barwick
Date:
Subject: Re: UPDATE table SET col = (SELECT ...)
Next
From: "Nicolas JOUANIN"
Date:
Subject: Re: TR: Like and =