Re: Referencing serial col's sequence for insert

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: Referencing serial col's sequence for insert
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B17D1EFB8@ntex2010i.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: Referencing serial col's sequence for insert  (David G Johnston <david.g.johnston@gmail.com>)
Ответы Re: Referencing serial col's sequence for insert  (Anil Menon <gakmenon@gmail.com>)
Список pgsql-general
David G Johnston 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).

You are right, I mixed it up with "currval".

Yours,
Laurenz Albe

В списке pgsql-general по дате отправления:

Предыдущее
От: David G Johnston
Дата:
Сообщение: Re: Referencing serial col's sequence for insert
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Fwd: Need r_constraint_name