From: | Matt <matt(at)kynx(dot)org> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | PL/pgsql - getting row from record |
Date: | 2004-11-16 12:21:04 |
Message-ID: | 1100607663.4227.33.camel@matt.kynx.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I'm sure this has been asked before, but my searches haven't come up
with an example.
I'm writing a generic trigger function called from different tables in
plpgsql that needs to get the value of the primary key column from OLD.
I can find out the pkey column name by querying the system tables, but
the only way I've found of getting the value of that column is by
creating a temporary table and using FOR ... EXECUTE to get the value
back out. My code for doing that is below, but it seems mighty ugly.
So, two questions:
1. Is there a better way of getting arbitrary columns from a record?
2. If not, will I run into problems with the name of the temporary table
if two processes call this function at the same time, or are temp names
unique to the particular session?
CREATE TEMPORARY TABLE get_colval_from_record_tmp
AS SELECT OLD.*;
FOR srow IN EXECUTE
''SELECT '' || col || '' AS scol
FROM get_colval_from_record_tmp''
LOOP
colval := srow.scol;
END LOOP;
DROP TABLE get_colval_from_record_tmp;
Thanks for the help,
Matt
BTW: I noticed on http://developer.postgresql.org/todo.php there's an
item "Allow PL/pgSQL to name columns by ordinal position, e.g. rec.(3)".
That'd do me fine, but I guess I'd better ask on the dev list as to when
this might happen :)
From | Date | Subject | |
---|---|---|---|
Next Message | Nils Rennebarth | 2004-11-16 12:21:35 | Controlling maximal on-disk size of a table |
Previous Message | Tatsuo Ishii | 2004-11-16 12:20:46 | Re: OID's |