Re: Getting consecutive sequence values

From: "Ed L(dot)" <pgsql(at)bluepolka(dot)net>
To: nolan(at)celery(dot)tssi(dot)com, pgsql-general(at)postgresql(dot)org (pgsql list)
Subject: Re: Getting consecutive sequence values
Date: 2003-04-04 22:24:46
Message-ID: 200304041524.46342.pgsql@bluepolka.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday April 4 2003 1:53, nolan(at)celery(dot)tssi(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-04-04 22:40:26 Re: Getting consecutive sequence values
Previous Message Ed L. 2003-04-04 22:11:58 Re: dbmirror revisions