Re: Any way to insert rows with ID used in another column - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Any way to insert rows with ID used in another column
Date
Msg-id CAF-3MvN1n2BweOk2mpRndViE0RODS84_=BS1sqjWGzUrQLcaag@mail.gmail.com
Whole thread Raw
In response to Any way to insert rows with ID used in another column  (Ben Hoyt <benhoyt@gmail.com>)
List pgsql-general
On 3 April 2014 16:41, Ben Hoyt <benhoyt@gmail.com> wrote:
> Hi folks,

> I tried using currval() to see if that'd work, but it gave an error, I guess
> because I was using it multiple times per session.

currval() requires that nextval() was called before it (either
automatically or explicitly) in the same transaction.

Usually what you want is achieved using nextval(). You request n new
ID's using nextval(), which you can then use to both name your n image
files and for the ID with which you will be inserting them into your
table.

Unfortunately there doesn't appear to be a variant of nextval() that
you pass a number which then subsequently returns a set of values,
that would be ideal for such usage, but that can be worked around by
calling nextval() in conjunction with generate_series().

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.


pgsql-general by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: Any way to insert rows with ID used in another column
Next
From: Torsten Förtsch
Date:
Subject: Re: Pagination count strategies