Re: Re: sequences - Mailing list pgsql-general

From Charles Tassell
Subject Re: Re: sequences
Date
Msg-id 4.3.2.7.2.20000921183640.00b8e5d0@mailer.isn.net
Whole thread Raw
In response to Re: sequences  ("K Parker" <kparker@eudoramail.com>)
List pgsql-general
 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


pgsql-general by date:

Previous
From: Richard Harvey Chapman
Date:
Subject: Re: problem with CREATE FUNCTION
Next
From: Charles Tassell
Date:
Subject: Re: Application data refreshing