Is it possible to programmatically retrieve the OID of a just-inserted
record in a PL/PGSQL function? Apparently, it is not currently
possible in psql, but I'm hoping C programming is not required for
this.
If so, can someone please demonstrate how this is done?
If not, can someone in the know definitely state the means by which it
is currently possible to do this?
Why would someone want to do this? Because it is the only way I know
of to definitively retrieve a newly-generated serial value for use as
the primary/foreign key (a *very* common RDBMS practice). Other
suggested approaches to skinning this cat are welcome. If PL/PGSQL
can't do this, it seems rather severely limited in its usefulness for
non-trivial databases. In this post,
http://www.postgresql.org/mhonarc/pgsql-general/1998-07/msg00203.html
Bruce Momjian says its possible for things using libpq "directly" to
retrieve the oid. Does PL/PGSQL use libpq directly?
This question has been asked in one form or another in a number of
posts in pgsql-general and pgsql-sql, but without any definitive
answers. I have experimented, scoured the mailing list archives, the
postgresql PL/pgSQL documentation, and deja.com to no avail, thus my
post here.
So, is it possible with PL/pgSQL? How? Thanks in advance...
Cheers,
Ed