Re: Getting OID after Insert

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Cota <bruce(at)vivi(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting OID after Insert
Date: 2001-10-18 18:01:44
Message-ID: 24807.1003428104@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruce Cota <bruce(at)vivi(dot)com> writes:
> Is there a way, in SQL, to access the oid of the row created
> by an immediately preceding insert statement?

If you are writing a psql script, recent psql versions maintain
a LASTOID variable:

regression=# insert into int4_tbl default values;
INSERT 3357467 1
regression=# select :LASTOID;
?column?
----------
3357467
(1 row)

regression=#

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Keary Suska 2001-10-18 18:03:35 Re: drop column
Previous Message Keary Suska 2001-10-18 18:01:04 Re: creating a custom server