Re: SQL-question: returning the id of an insert querry

Поиск
Список
Период
Сортировка
От Scott Chapman
Тема Re: SQL-question: returning the id of an insert querry
Дата
Msg-id 200311100809.29103.scott_list@mischko.com
обсуждение исходный текст
Ответ на Re: SQL-question: returning the id of an insert querry  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Ответы Re: SQL-question: returning the id of an insert querry  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Re: SQL-question: returning the id of an insert querry  ("David Green" <david@sagerobot.com>)
Список pgsql-general
On Sunday 09 November 2003 10:52, Alvaro Herrera wrote:
> On Sun, Nov 09, 2003 at 10:26:51AM -0800, Scott Chapman wrote:
> > On Sunday 09 November 2003 03:13, Martijn van Oosterhout wrote:
> > > After you've done the insert on the address table, you can use
> > > currval('address_id_seq') (or equivalent) to get the ID. Ofcourse
> > > you have to have used nextval() for the original insert.
> >
> > What if someone else inserts another address before I get the
> > currval? I'm out of luck then, right?
>
> No, currval is concurrency-safe.  That's exactly what sequences are
> for.

I just want to clarify what I mean here to make sure I understand this
right. I have a table, A, that has a ID field which defaults to nextval
of a sequence, SA.

Chronological events here:

X inserts a new record into A.
Y inserts a new record into A.
X fetches currval of the SA. What value does X get in this case, the one
from X's insert or Y's?

Scott



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Dynamic expression evaluation
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: SQL-question: returning the id of an insert querry