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

Ref to last INSERT on a table without OIDs?

From
"Mark Cave-Ayland"
Date:
Hi there,

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.


Many thanks,

Mark.

---

Mark Cave-Ayland
Webbased Ltd.
Tamar Science Park
Derriford
Plymouth
PL6 8BX
England

Tel: +44 (0)1752 764445
Fax: +44 (0)1752 764446


This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender. You
should not copy it or use it for any purpose nor disclose or distribute
its contents to any other person.


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

From
Neil Conway
Date:
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@samurai.com> || PGP Key ID: DB3C29FC




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

From
"Mark Cave-Ayland"
Date:
Thanks Neil,

That was exactly the clarification I was looking for - I'll try reading
through the manual a bit more closely next time!


Cheers,

Mark.


---

Mark Cave-Ayland
Webbased Ltd.
Tamar Science Park
Derriford
Plymouth
PL6 8BX
England

Tel: +44 (0)1752 764445
Fax: +44 (0)1752 764446


This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender. You
should not copy it or use it for any purpose nor disclose or distribute
its contents to any other person.