From: Rich Cullingford <rculling@sysd.com>
To: pgsql-interfaces@postgresql.org
Subject: Tantalizing reference to passing data from NEW variable in a trigger function...
Date: Mon, 26 Apr 2004 11:38:13 -0400
Message-ID: <408D2CE5.1090108@sysd.com> (raw)
All,
This question seems to have been asked a number of times on this list,
recently (including by me) without being answered: how to pass the row
data stored in the NEW variable from a trigger function into a
sub-function. None of the obvious syntaxes work, including one by a
respondent in this list that suggested assigning NEW to a record
variable, and then passing *that*. After searching up and down the
archives, I see the following tantalizing snippet (from 6/2003) in the
context of a rule:
Gunter Diehl <gdid ( at ) gmx ( dot ) 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?
^^^^^
If there's a page somewhere that says how to do this, I'd be extremely
grateful for a pointer. The obvious maneuver of copying NEW's data
field-by-field into a composite variable is rather unappetizing when the
row is wide...
Rich Cullingford
rculling@sysd.com
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-interfaces@postgresql.org
Cc: rculling@sysd.com
Subject: Re: Tantalizing reference to passing data from NEW variable in a trigger function...
In-Reply-To: <408D2CE5.1090108@sysd.com>
* 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