Re: BUG #3811: Getting multiple values from a sequence generator - Mailing list pgsql-bugs

From Gregory Stark
Subject Re: BUG #3811: Getting multiple values from a sequence generator
Date
Msg-id 873auahk5p.fsf@oxford.xeocode.com
Whole thread Raw
In response to BUG #3811: Getting multiple values from a sequence generator  ("Adriaan van Os" <postgres@microbizz.nl>)
Responses Re: BUG #3811: Getting multiple values from a sequence generator
List pgsql-bugs
"Adriaan van Os" <postgres@microbizz.nl> writes:

> Right, I want to use it with a bulk operation, say importing a million records
> with COPY. Calling nextval one million times looks to me like an enormous waste
> of resources. Suppose, you are on an ADSL line: it will cost one million times
> the ping time of the ADSL line (say 10 milliseconds per call). Well OK, one
> could write a server function that does this, but then the one million result
> values must be transported back to the client, because they are not guaranteed
> to be contiguous. Unneeded complexity compared to a simple nextval increment
> parameter.

The usual way to use nextval() is to use it on the server as an expression in
an INSERT or DEFAULT. If you're using COPY and don't have a column default set
up then, hm, I guess you're kind of stuck. That would make a good use case for
a one-time nextval(increment) or something like that.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's PostGIS support!

pgsql-bugs by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: why "alter table" to change owner of sequence?
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: BUG #3811: Getting multiple values from a sequence generator