From: | Jille Timmermans <jille(at)quis(dot)cx> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Support for grabbing multiple consecutive values with nextval() |
Date: | 2022-03-03 09:21:05 |
Message-ID: | 78935e29849ab347948b3d4f80c15fe0@quis.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2022-03-03 10:10, Peter Eisentraut wrote:
> On 02.03.22 20:12, Jille Timmermans wrote:
>> 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 don't understand this use case. COPY FROM copies from a file. So
> you want to preallocate the sequence numbers before you copy the new
> data in?
Yes
> How do you know how many rows are in the file?
I'm using https://pkg.go.dev/github.com/jackc/pgx/v4#Conn.CopyFrom,
which uses the COPY FROM protocol but doesn't actually have to originate
from a file.
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2022-03-03 09:30:19 | Re: Proposal: Support custom authentication methods using hooks |
Previous Message | kuroda.hayato@fujitsu.com | 2022-03-03 09:18:46 | RE: Logical replication timeout problem |