Re: [INTERFACES] locking on database updates - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: [INTERFACES] locking on database updates
Date
Msg-id 23996.944589573@sss.pgh.pa.us
Whole thread Raw
In response to Re: [INTERFACES] locking on database updates  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
Responses Re: [INTERFACES] locking on database updates  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
List pgsql-interfaces
"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 doselect 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


pgsql-interfaces by date:

Previous
From: Tom Lane
Date:
Subject: Re: [INTERFACES] locking on database updates
Next
From: Tom Lane
Date:
Subject: Re: [INTERFACES] Deleting duplicate records