X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 78877D1E9DC for ; Mon, 5 Apr 2004 17:01:08 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 58859-04 for ; Mon, 5 Apr 2004 14:01:35 -0300 (ADT) Received: from server.fortbsd.dsl.enter.net (dhcp-site-225-1384-66.msns.sm.ptd.net [24.229.225.150]) by svr1.postgresql.org (Postfix) with ESMTP id 9991CD1D5E4 for ; Mon, 5 Apr 2004 14:01:02 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by server.fortbsd.dsl.enter.net (Postfix) with ESMTP id 4F335AAEA for ; Mon, 5 Apr 2004 13:01:40 -0400 (EDT) Received: from server.fortbsd.dsl.enter.net ([127.0.0.1]) by localhost (server.fortbsd.dsl.enter.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 07924-02 for ; Mon, 5 Apr 2004 13:01:40 -0400 (EDT) Received: from www.grabias.com (localhost [127.0.0.1]) by server.fortbsd.dsl.enter.net (Postfix) with SMTP id F00EAAAE9 for ; Mon, 5 Apr 2004 13:01:39 -0400 (EDT) Received: from 63.65.2.36 (SquirrelMail authenticated user gaving) by www.grabias.com with HTTP; Mon, 5 Apr 2004 13:01:39 -0400 (EDT) Message-ID: <50616.63.65.2.36.1081184499.squirrel@www.grabias.com> Date: Mon, 5 Apr 2004 13:01:39 -0400 (EDT) Subject: Function To Log Changes From: "Gavin" To: pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Virus-Scanned: by amavisd-new at grabias.com X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/14 X-Sequence-Number: 17389 Hi All, I have been tinkering with a function to log the changes made on any column through a function and trigger. However, I cant think of a way to make this work through pl/pgsql. Any one have any ideas, or is it just not possible? SNIP create or replace function logchange2() returns OPAQUE as ' DECLARE columnname record; c2 VARCHAR(64); BEGIN /* Cycle through the column names so we can find the changes being made */ FOR columnname IN SELECT attname FROM pg_attribute, pg_type WHERE attnum > 0 AND typrelid=attrelid AND typname=''SOMETABLE'' LOOP c2 := CAST(columnname.attname AS VARCHAR(64)); /* here lies the problem. How would I make plpgsql see OLD.columnname in a dynamic fashion. I know this wont work whats below, but I am just trying to express what I am trying to do */ IF ''OLD.'' || c2 != ''NEW.'' || c2 THEN /* IF CHANGED DO SOMETHING */ RAISE NOTICE ''Update on column %'', c2; END IF; END LOOP; return NULL; END; ' LANGUAGE plpgsql; create trigger logchange2 AFTER UPDATE on TABLENAME FOR EACH ROW EXECUTE PROCEDURE logchange2();