Re: SQL Help - Obtaining ID of record INSERTED

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 17, 2005 at 08:39:22AM -0400, josh@xxxxxxxxxxxxxxxx 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


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux