pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
Cc: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: 'Pgsql Interfaces' <pgsql-interfaces@postgreSQL.org>
Subject: Re: [INTERFACES] locking on database updates
Date: Tue, 07 Dec 1999 12:59:33 -0500
Message-ID: <23996.944589573@sss.pgh.pa.us> (raw)
In-Reply-To: <19991207111234.A6021@rice.edu>

"Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu> writes:
> create table foo (bar serial, baz text);
> insert into foo (baz) values ('wooble');
> select currval('foo_bar_seq');

I don't think this is safe in a multi-client environment;
what if someone else inserts at about the same time?

Better to do
	select nextval('foo_bar_seq');
	insert into foo values (just-retrieved-value, 'wooble');
which is safer and probably marginally faster (since the
sequence object is touched only once, not twice).

			regards, tom lane



view thread (21+ messages)  latest in thread

Message-ID: <23996.944589573@sss.pgh.pa.us>
Permalink:  ../23996.944589573@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23996.944589573@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: tgl@sss.pgh.pa.us, reedstrm@wallace.ece.rice.edu, gary.stainburn@ringways.co.uk
  Subject: Re: [INTERFACES] locking on database updates
  In-Reply-To: <23996.944589573@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox