From: Charles Tassell <ctassell@isn.net>
To: kparker@eudoramail.com
To: pgsql-general@hub.org
Subject: Re: Re: sequences
Date: Thu, 21 Sep 2000 18:45:00 -0300
Message-ID: <4.3.2.7.2.20000921183640.00b8e5d0@mailer.isn.net> (raw)
In-Reply-To: <IIKDHBOLMPKLCAAA@shared1-mail.whowhere.com>
From memory of previous discussions, what a sequence actually does is
guarantee you a unique value, although those vales may not actually occur
in numeric order (ie, a record put in at 1:10pm might get a sequence value
of 12, one at 1:11 might get 15, and a third at 1:12 might get 13.) This
is because each backend allocates it's own block of values within a
sequence when it sees that it's going to need to use it (or at least used
to with 6.5, dunno if it was changed in 7.) So if your first backend
opens up, uses a sequence, then you putter around for a couple more minutes
doing other selects/updates/whatever commands on the same connection, then
use the sequence again, your two values will probably be consecutive. If
in the middle of that putterring around another backend came in and used
the sequence though, it's going to get a higher value than both the
sequences of the previous connection, even if it uses the sequence before
the second one of the first connection. I'm not sure how this is effected
by transactions / no transactions, but this is how someone explained it to
me a few months ago.
If you really want to test it though, open up two psql connections at the
same time in different terminals and try some insert's to see what you
get. Might want to try it both inside and outside of transaction blocks
just in case.
At 03:13 AM 9/21/00, K Parker wrote:
>Edward Q. Bridges's detailed statement regarding sequences, of which I
>extract merely the most pessimistic part:
>
> > begin;
> > insert into foo (A,B) values (B);
> > select currval('foo_A_seq');
> > commit;
> >
> > note that the transaction is key, without
> > which there's no guarantee that some other
> > statement will affect the value of the
> > sequence.
>
>quite clearly conflicts what what seems to me to be the plain meaning of
>the manual page for CREATE SEQUENCE which states, in part:
>
> > multiple backends are guaranteed to
> > allocate distinct sequence values
>
>Can some knowledgable person here save a bunch of us plain old
>user-programmers the trouble of trying to trace down what the source says
>and just clarify this issue? Thanks!
> >
>
>
>Join 18 million Eudora users by signing up for a free Eudora Web-Mail
>account at http://www.eudoramail.com
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-general@postgresql.org
Cc: ctassell@isn.net, kparker@eudoramail.com, pgsql-general@hub.org
Subject: Re: sequences
In-Reply-To: <4.3.2.7.2.20000921183640.00b8e5d0@mailer.isn.net>
References: <IIKDHBOLMPKLCAAA@shared1-mail.whowhere.com> <4.3.2.7.2.20000921183640.00b8e5d0@mailer.isn.net>
* 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