[HACKERS] How to get OID from INSERT in PL/PGSQL?

From: Ed Loehr <ELOEHR(at)austin(dot)rr(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [HACKERS] How to get OID from INSERT in PL/PGSQL?
Date: 1999-11-28 19:45:19
Message-ID: 3841864F.F4642DC6@austin.rr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Oliver Elphick 1999-11-28 19:50:55 UNION not allowed in sub-selects?
Previous Message Tom Lane 1999-11-28 17:44:14 Re: [HACKERS] Development installation fails