Re: sequence caches - Mailing list pgsql-general

From Tom Lane
Subject Re: sequence caches
Date
Msg-id 460.1053454154@sss.pgh.pa.us
Whole thread Raw
In response to Re: sequence caches  (jks@selectacast.net)
List pgsql-general
jks@selectacast.net writes:
>> Seems that would require predicting the future.  How would you know how
>> many times the sequence would get nextval'd in one query?

> Because you parse the query before you take any action, so you know how
> many times the nextval will be called.

No you don't.  Consider CASE expressions, SELECTs that will return an
uncertain number of rows, etc.

> Or do you do the locking down in
> the nextval method that knows nothing about the other nextvals?

Exactly.

> Perhaps
> there could be a function call that retrieves X sequence numbers from the
> sequence that overrides the cache settings so I could query like:
> SELECT nextval('seqname',3),nextval('seqname'),nextval('seqname');

Doesn't really seem worth the trouble to me.  To take just one obvious
problem, what makes you think that those expressions will be evaluated
left-to-right?  There are no guarantees of execution order in SQL.

            regards, tom lane

pgsql-general by date:

Previous
From: jks@selectacast.net
Date:
Subject: Re: sequence caches
Next
From: Rod Taylor
Date:
Subject: Re: sequence caches