From: Markus Wagner <wagner@imsd.uni-mainz.de>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: evaluating values of attributes from computed attribute names in trigger function
Date: Wed, 20 Jun 2001 14:53:32 +0200
Message-ID: <3B309CCC.2CCFA2DB@imsd.uni-mainz.de> (raw)
Hi,
I need to find all changed fields in a trigger function. I found out how
to get the names of all attributes within plpgsql, but I cannot get the
value of NEW and OLD for the attribute with that name.
That is:
assume there is NEW.foo and OLD.foo
let the name 'foo' be computed and stored in variable attrname:
attrname='foo'
Then, if I write NEW.attrname, it is confused with an attribute called
'attrname'.
So how can I get the changed fields in my row?
Please see my function below.
Thank you very much,
Markus
CREATE FUNCTION trg_001() RETURNS OPAQUE AS
'
DECLARE
rec RECORD;
BEGIN
FOR rec IN SELECT a.attname AS atr FROM pg_attribute
a,pg_class c WHERE a.attrelid = c.oid AND a.attnum > 0 AND
c.relname=TG_RELNAME LOOP
IF NEW.atr <> OLD.atr THEN
INSERT INTO test (txt) VALUES (rec.atr);
END IF;
END LOOP;
RETURN NEW;
END;
'
LANGUAGE 'plpgsql';
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-sql@postgresql.org
Cc: wagner@imsd.uni-mainz.de
Subject: Re: evaluating values of attributes from computed attribute names in trigger function
In-Reply-To: <3B309CCC.2CCFA2DB@imsd.uni-mainz.de>
* 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