Re: Support for grabbing multiple consecutive values with nextval() - Mailing list pgsql-hackers

From Jille Timmermans
Subject Re: Support for grabbing multiple consecutive values with nextval()
Date
Msg-id 86187a01dee0883714c8ee7eec4c5a40@quis.cx
Whole thread Raw
In response to Re: Support for grabbing multiple consecutive values with nextval()  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
Responses Re: Support for grabbing multiple consecutive values with nextval()
List pgsql-hackers
On 2022-02-28 11:13, Peter Eisentraut wrote:
> On 27.02.22 10:42, Jille Timmermans wrote:
>> I wanted to be able to allocate a bunch of numbers from a sequence at 
>> once. Multiple people seem to be struggling with this 
>> (https://stackoverflow.com/questions/896274/select-multiple-ids-from-a-postgresql-sequence, 
>> https://www.depesz.com/2008/03/20/getting-multiple-values-from-sequences/).
>> 
>> I propose to add an extra argument to nextval() that specifies how 
>> many numbers you want to allocate (default 1).
> 
> What is the use of this?
> 
> I note that the stackoverflow question wanted to return multiple
> sequence values as a result set, whereas your implementation just
> skips a number of values and returns the last one.  At least we should
> be clear about what we are trying to achieve.
Both would work for me actually. I'm using COPY FROM to insert many rows 
and need to know their ids and COPY FROM doesn't support RETURNING.

I implemented this approach because:
- smaller diff
- maybe someone benefits from them being consecutive
- less data to send between client/server

The obvious downside is that people can make mistakes in whether the 
returned number is the first or last number of the series.



pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: [PATCH] Add reloption for views to enable RLS
Next
From: Chapman Flack
Date:
Subject: Re: Postgres restart in the middle of exclusive backup and the presence of backup_label file