Received: from yara.imsd.uni-mainz.de (yara.IMSD.Uni-Mainz.DE [134.93.144.68]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5KCu8a83475 for ; Wed, 20 Jun 2001 08:56:08 -0400 (EDT) (envelope-from wagner@imsd.uni-mainz.de) Received: (from smap@localhost) by yara.imsd.uni-mainz.de (8.9.3/8.9.3/lxs_5.2) id OAA06704 for ; Wed, 20 Jun 2001 14:55:20 +0200 Received: from hermes.imsd.uni-mainz.de(134.93.64.80) by yara.imsd.uni-mainz.de via smap (V2.1/2.1+anti-relay+anti-spam) id xma006675; Wed, 20 Jun 01 14:54:50 +0200 Received: from imsd.uni-mainz.de (unverified [134.93.64.34]) by hermes.imsd.uni-mainz.de (EMWAC SMTPRS 0.83) with SMTP id ; Wed, 20 Jun 2001 14:54:02 +0200 Message-ID: <3B309CCC.2CCFA2DB@imsd.uni-mainz.de> Date: Wed, 20 Jun 2001 14:53:32 +0200 From: Markus Wagner Organization: IMSD X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.13 i686) X-Accept-Language: en MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: evaluating values of attributes from computed attribute names in trigger function Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200106/301 X-Sequence-Number: 3564 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';