Re: currval() in insert statements - Mailing list pgsql-general

From Craig Ringer
Subject Re: currval() in insert statements
Date
Msg-id 49982164.6060506@postnewspapers.com.au
Whole thread Raw
In response to currval() in insert statements  (Onno Molenkamp <onno@flox.org>)
List pgsql-general
Onno Molenkamp wrote:
> Hi,
>
> I recently upgraded a database from 8.1.11 to 8.3.6, and I noticed the
> following statement stopped working:
>
>   insert into test (b) select currval('test_a_seq'::regclass)

It's generally a REALLY bad idea to mix `nextval' and `currval' use on
the same sequence in a single SQL statement.

Personally, in the one case in the project I'm working on where I DO
need to INSERT a generated ID in two places I use a trigger to take care
of it.

--
Craig Ringer

pgsql-general by date:

Previous
From: Bjørn T Johansen
Date:
Subject: How do I set the schema search path in a datasource config for a connection pool?
Next
From: Osvaldo Kussama
Date:
Subject: Re: Array in nested query