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

From Tom Lane
Subject Re: currval() in insert statements
Date
Msg-id 3051.1234629665@sss.pgh.pa.us
Whole thread Raw
In response to currval() in insert statements  (Onno Molenkamp <onno@flox.org>)
List pgsql-general
Onno Molenkamp <onno@flox.org> writes:
> 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 doesn't work in 8.1 either:

Welcome to psql 8.1.16, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

regression=# create table test (a serial, b int);
NOTICE:  CREATE TABLE will create implicit sequence "test_a_seq" for serial column "test.a"
CREATE TABLE
regression=# insert into test (b) select currval('test_a_seq'::regclass);
ERROR:  currval of sequence "test_a_seq" is not yet defined in this session
regression=#

There must be something else that you changed about your application.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: trigger creation error (tsvector_update_trigger)
Next
From: Carlos Henrique Reimer
Date:
Subject: Track a function