Specify a column without using its name

From: Andrew Biagioni <andrew(dot)biagioni(at)e-greek(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Specify a column without using its name
Date: 2003-11-30 23:39:25
Message-ID: ZY4Z2X6Z183BOKMLSMDAJIFDHGOK.3fca7fad@Laptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all!

I'm trying to write a general-purpose trigger that determines what fields have
changed during an UPDATE, but I'm running into a problem.

I'm trying to dynamically select the value from a field in "old" and "new" (the
old and new values for the changed row), but I can't figure out how to do so.

I tried something like,

qry := ''SELECT '' || fieldname || '' AS curval FROM old'';
FOR rec IN EXECUTE qry LOOP
fieldval := rec.curval;
EXIT;
END LOOP;

but it doesn't work ("ERROR: OLD used in non-rule query").

Any suggestions?

Thanks,

Andrew

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2003-11-30 23:42:53 Re: Was: Triggers, Stored Procedures, PHP
Previous Message Alvaro Herrera 2003-11-30 23:32:06 Re: pg_hba.conf problem