Ref to last INSERT on a table without OIDs?

Started by Mark Cave-Aylandover 23 years ago3 messagesgeneral
Jump to latest
#1Mark Cave-Ayland
mark.cave-ayland@webbased.co.uk

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.

#2Neil Conway
neilc@samurai.com
In reply to: Mark Cave-Ayland (#1)
Re: Ref to last INSERT on a table without OIDs?

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

#3Mark Cave-Ayland
mark.cave-ayland@webbased.co.uk
In reply to: Neil Conway (#2)
Re: Ref to last INSERT on a table without OIDs?

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.