From: Michael Fuhr <mike@fuhr.org>
To: josh@segrestfarms.com <josh@segrestfarms.com>
Cc: Jason Minion <jason.minion@sigler.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: SQL Help - Obtaining ID of record INSERTED
Date: Wed, 17 Aug 2005 06:56:00 -0600
Message-ID: <20050817125600.GA19186@winnie.fuhr.org> (raw)
In-Reply-To: <43032FFA.5070108@segrestfarms.com>
References: <0105A1BF505D304E9E5AF38B63E40E4E807FC2@EXCHANGE.siglercompanies.com>
<43032FFA.5070108@segrestfarms.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: mike@fuhr.org, josh@segrestfarms.com, jason.minion@sigler.com
Subject: Re: SQL Help - Obtaining ID of record INSERTED
In-Reply-To: <20050817125600.GA19186@winnie.fuhr.org>
References: <0105A1BF505D304E9E5AF38B63E40E4E807FC2@EXCHANGE.siglercompanies.com> <43032FFA.5070108@segrestfarms.com> <20050817125600.GA19186@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox