Specify a column without using its name

Started by Andrew Biagioniover 22 years ago3 messagesgeneral
Jump to latest
#1Andrew Biagioni
andrew.biagioni@e-greek.net

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Biagioni (#1)
Re: Specify a column without using its name

Andrew Biagioni <andrew.biagioni@e-greek.net> writes:

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.

You cannot do this in plpgsql. It's possible in pltcl though.

regards, tom lane

#3Andrew Biagioni
andrew.biagioni@e-greek.net
In reply to: Tom Lane (#2)
Re: Specify a column without using its name

Tom Lane wrote:

Andrew Biagioni <andrew.biagioni@e-greek.net> writes:

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.

You cannot do this in plpgsql. It's possible in pltcl though.

That's great! Um... how? I'm a pl/tcl novice... Actually I'm also a
tcl novice!

Thanks,

Andrew

Show quoted text

regards, tom lane