Re: currval() in insert statements

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Onno Molenkamp <onno(at)flox(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: currval() in insert statements
Date: 2009-02-15 14:06:28
Message-ID: 49982164.6060506@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Osvaldo Kussama 2009-02-15 15:16:31 Re: Array in nested query
Previous Message Bjørn T Johansen 2009-02-15 12:58:56 How do I set the schema search path in a datasource config for a connection pool?