Re: currval of sequence xxx_seq is not yet defined in this session?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: kenyon <lqchenzjut(at)sina(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: currval of sequence xxx_seq is not yet defined in this session?
Date: 2013-01-07 16:09:26
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

kenyon <lqchenzjut(at)sina(dot)com> writes:
> recently i found some errors in pg_log when i do some pressure testing,looks
> like

> "2013-01-05 21:48:29.870
> CST,"postgres","wedding",15850,"",50e82f2d.3dea,1,"SELECT",2013-01-05
> 21:48:29 CST,19/80509,0,ERROR,55000,"currval of sequence
> ""t_wedding_wedding_id_seq"" is not yet defined in this session"
> ,,,,,," SELECT currval('t_wedding_wedding_id_seq')as weddingId
> ",,,""

This implies that currval('t_wedding_wedding_id_seq') is being called
before any nextval('t_wedding_wedding_id_seq') has been done in the
current session. It has nothing to do with sequence cache properties;
it's an application programming error, plain and simple.

> the code is

> begin;
> insert into t_wedding(wedding_id,share_id,share_type,user_id,wedding_time)
> select nextval('t_wedding_wedding_id_seq')
> ,#ShareId#,#shareType#,#userId#,#weddingTime#
> <selectKey resultClass="int" keyProperty="weddingId">
> SELECT currval('t_wedding_wedding_id_seq')as weddingId
> </selectKey>
> ;

I don't know what the HTML-ish markup in that is supposed to mean, but
if what it means is that some piece of client-side code is pulling out
the contained query and using it separately, you need to trace what that
logic is doing exactly. Because it sure looks like it's using the
SELECT query wrongly --- either before the INSERT has been done, or
perhaps in a different connection.

regards, tom lane

In response to


Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2013-01-07 16:18:42 Re: lc_time not working?
Previous Message Tom Lane 2013-01-07 15:56:26 Re: lc_time not working?