Re: Getting consecutive sequence values - Mailing list pgsql-general

From Ed L.
Subject Re: Getting consecutive sequence values
Date
Msg-id 200304041524.46342.pgsql@bluepolka.net
Whole thread Raw
In response to Re: Getting consecutive sequence values  (nolan@celery.tssi.com)
List pgsql-general
On Friday April 4 2003 1:53, nolan@celery.tssi.com wrote:
> > select setval('id',nextval('id')+100)
>
> That's certainly tidier than my lengthy SQL statement, but I don't know
> that it solves the concurrent access issue.  What happens if a 2nd call
> to nextval is issued at the same time?

Have you considered creating a sequence object with a cache size of 100?

    CREATE SEQUENCE id CACHE 100;

This will cause the sequence number to be handed in groups of 100, whatever
the next available group of 100 is, and when that is exhausted, it'll do
what you'd expect.  So if session 1 grabs a value, it gets ids 1-100, and
then session 2 gets 101-200, and then if session 1 runs out and grabs
another, it automatically gets 201-300.

Ed


pgsql-general by date:

Previous
From: "Ed L."
Date:
Subject: Re: dbmirror revisions
Next
From: nolan@celery.tssi.com
Date:
Subject: Re: dbmirror revisions