Re: wishlist for 8.4 - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: wishlist for 8.4
Date
Msg-id 47B595AD.5040602@enterprisedb.com
Whole thread Raw
In response to wishlist for 8.4  (Raphaël Jacquot <sxpert@sxpert.org>)
List pgsql-hackers
Raphaël Jacquot wrote:
> I recently found myself trying to build a trigger to modify some fields 
> in a good dozen similarly structured tables in which the similar columns 
> had different names.
> in fact, I got stuck in pl/pgsql with the fact that there's no way to 
> access the NEW tuple in an indirect way, having the name of the column 
> in some variable. (I found that it could be done in plperl, but that 
> left me with a taste of un-completeness...)

It's ugly, but you could play tricks with EXECUTE. Like:

CREATE OR REPLACE FUNCTION emp_stamp() RETURNS trigger AS $emp_stamp$
DECLARE    empname text;
BEGIN    EXECUTE 'SELECT ('''||new||'''::emp).empname' INTO empname;    RAISE NOTICE 'new empname is: %', empname;
RETURNNEW;
 
END;
$emp_stamp$ LANGUAGE plpgsql;

Not sure the quoting is right...

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Sam Mason
Date:
Subject: Re: wishlist for 8.4
Next
From: "Roberts, Jon"
Date:
Subject: Re: subquery in limit