Re: SQL Help - Obtaining ID of record INSERTED

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: SQL Help - Obtaining ID of record INSERTED
Дата
Msg-id 20050817125600.GA19186@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: SQL Help - Obtaining ID of record INSERTED  ("josh@segrestfarms.com" <josh@segrestfarms.com>)
Список pgsql-admin
On Wed, Aug 17, 2005 at 08:39:22AM -0400, josh@segrestfarms.com wrote:
> You stated that the SELECT currval('orderid_id_seq') statement is a
> separate query and must be treated as such.
>
> This gives me cause for concern.  My intention is to obtain the orderid
> of the order inserted at that moment, but if I am to use a separate
> query it would seem there is a chance (albeit a small one) that another
> order could come through before I am able to obtain the orderid.

No, there isn't; or rather, it doesn't matter.  See the documentation
and the FAQ.

http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html

  Return the value most recently obtained by nextval for this
  sequence in the current session.  (An error is reported if nextval
  has never been called for this sequence in this session.)  Notice
  that because this is returning a session-local value, it gives a
  predictable answer whether or not other sessions have executed
  nextval since the current session did.

http://www.postgresql.org/docs/faqs.FAQ.html#4.11.3

  4.11.3) Doesn't currval() lead to a race condition with other users?

  No.  currval() returns the current value assigned by your session,
  not by all sessions.

--
Michael Fuhr

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

Предыдущее
От: "josh@segrestfarms.com"
Дата:
Сообщение: Re: SQL Help - Obtaining ID of record INSERTED
Следующее
От: Sivakumar K
Дата:
Сообщение: Re: error codes in postgresql