From: | David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Referencing serial col's sequence for insert |
Date: | 2014-07-22 14:24:42 |
Message-ID: | 1406039082942-5812382.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Albe Laurenz *EXTERN* wrote
> Also, I think that your method is vulnerable to race conditions:
> If somebody else increments the sequence between the INSERT and
> "SELECT lastval()" you'd get a wrong value.
Uh, no. It returns that last value issued in the same session - which is
race-proof.
http://www.postgresql.org/docs/9.3/static/functions-sequence.html
Both of them are useful and in the case of inserting multiple rows you have
to use RETURNING. Beyond though it is largely personal preference and
ease-of-use (dealing with a set when you know a single value is all that is
necessary can be annoying).
David J.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Referencing-serial-col-s-sequence-for-insert-tp5812225p5812382.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.
From | Date | Subject | |
---|---|---|---|
Next Message | rob stone | 2014-07-22 14:30:55 | Re: Referencing serial col's sequence for insert |
Previous Message | Ramesh T | 2014-07-22 14:21:10 | Fwd: Need r_constraint_name |