Re: [INTERFACES] locking on database updates

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
Cc: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>, "'Pgsql Interfaces'" <pgsql-interfaces(at)postgreSQL(dot)org>
Subject: Re: [INTERFACES] locking on database updates
Date: 1999-12-07 17:59:33
Message-ID: 23996.944589573@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

"Ross J. Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)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

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Tom Lane 1999-12-07 18:01:54 Re: [INTERFACES] Deleting duplicate records
Previous Message Tom Lane 1999-12-07 17:45:35 Re: [INTERFACES] locking on database updates