Re: Ref to last INSERT on a table without OIDs?

From: Neil Conway <neilc(at)samurai(dot)com>
To: Mark Cave-Ayland <mark(dot)cave-ayland(at)webbased(dot)co(dot)uk>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Ref to last INSERT on a table without OIDs?
Date: 2003-01-29 18:16:09
Message-ID: 1043864169.519.11.camel@tokyo
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2003-01-27 at 10:59, Mark Cave-Ayland wrote:
> Hopefully just a quick one: how is it possible to obtain a reference to
> the last inserted record in a table which is created without oids? I
> would like to dump/restore some of our larger tables so they don't use
> oids, however I am concerned that simply getting the current PK sequence
> value after insertion within a transaction is not safe when many people
> are accessing the table/sequence at once? Can anyone clarify this? We're
> using the latest and greatest 7.3.1.

currval() is safe even in the face of concurrent insertions into the
table: it always returns the last value that the sequence generated in
the current session, regardless of whether any additional values have
been generated from the sequence by other clients.

See the docs on currval() for more information:

http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/functions-sequence.html

Cheers,

Neil
--
Neil Conway <neilc(at)samurai(dot)com> || PGP Key ID: DB3C29FC

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron St.Pierre 2003-01-29 18:19:09 Re: is_numeric() or extract_numeric() functions?
Previous Message Ivar 2003-01-29 18:04:37 Postgre vs SAP Db