From: | Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com> |
---|---|
To: | Onno Molenkamp <onno(at)flox(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: currval() in insert statements |
Date: | 2009-02-14 13:41:44 |
Message-ID: | 2f4958ff0902140541w7952fd92i1ffd380bd7c15929@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
nextval.
currval only has value, when sequence wwas used in the session before,
you would use it to obtain last value returened by nextval. read the
manual .
On Sat, Feb 14, 2009 at 11:25 AM, Onno Molenkamp <onno(at)flox(dot)org> 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)
>
> given the following table:
>
> create table test (a serial, b int)
>
> The error I'm getting is: "ERROR: currval of sequence "test_a_seq" is not yet
> defined in this session". With a values clause instead of a select, it still
> works as expected, by inserting two identical values:
>
> insert into test (b) values (currval('test_a_seq'::regclass))
>
> Although it's easy enough to work around this problem by also explicitly
> inserting nextval('test_a_seq'::regclass) into column "a", I'm wondering why
> it did work in 8.1 and doesn't work anymore in 8.3.
>
> Is this a bug in either version, was is never supposed to work like this, or
> have I missed a change in the release notes somewhere?
>
> Thanks,
>
> Onno
>
--
GJ
From | Date | Subject | |
---|---|---|---|
Next Message | Onno Molenkamp | 2009-02-14 13:50:22 | Re: currval() in insert statements |
Previous Message | Onno Molenkamp | 2009-02-14 11:25:59 | currval() in insert statements |