Re: arbitrary number of values from a sequence - Mailing list pgsql-general

From Tom Lane
Subject Re: arbitrary number of values from a sequence
Date
Msg-id 27034.989000767@sss.pgh.pa.us
Whole thread Raw
In response to Re: arbitrary number of values from a sequence  ("Gyozo Papp" <pgerzson@freestart.hu>)
List pgsql-general
"Gyozo Papp" <pgerzson@freestart.hu> writes:
> Does it mean that it can't be ensured that returning values of
> nextval() are consecutive ones?

I think it would be folly to assume that, even with a cache setting
equal to the number of values you intend to fetch.  If the cache gets
out of sync with your requests (say, because a transaction aborted after
fetching just some of the 5 values) then subsequent transactions would
reload the cache partway through, and in that case you could get
non-consecutive results.

> does it help me if I set the transaction isolation level to
> serializable or lock the table of the sequence?

No.  Why do you need such a thing, anyway?  If you are always allocating
groups of 5 IDs, why don't you just pretend each nextval() gives you
five items instead of one?  You could simply multiply the returned value
by 5.  Or set the sequence's increment to 5.

            regards, tom lane

pgsql-general by date:

Previous
From: "WT Medewerker"
Date:
Subject: Re: How to install on Windows?
Next
From: Hualin Yip
Date:
Subject: how to start postgresql server ( or postmaster ) automatically