pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: currval() race condition on server?
Date: Mon, 23 Oct 2006 17:04:04 +0300
Message-ID: <200610231704.05113.achill@matrix.gatewaynet.com> (raw)
In-Reply-To: <453CC859.8070306@albourne.com>
References: <453CC859.8070306@albourne.com>

Óôéò ÄåõôÝñá 23 Ïêôþâñéïò 2006 16:49, ï/ç Adriaan Joubert Ýãñáøå:
> Hi,
>
> 	I've run into an intermittent problem with our code recently. We have
> the following set-up:
>
> table A : some data table
> table B : a history table for table A
>
> A trigger copies the old version of a row into table B whenever an
> update is done on table A. Both A and B contain an audit number, and the
> trigger obtains an audit number from a sequence and inserts it into the
> row inserted into table A.

What do you mean here? Inserts it into the row inserted....

>
> For some bookkeeping purposes I need the new audit number back from the
> update, so I submit a prepared statement through jdbc of the form
>
> UPDATE A SET ....; SELECT currval('ip_audit_seq');
>
> On the first call I get
>
>   ERROR: currval of sequence "ip_audit_seq" is not yet defined in this
> session

That normally means that no nextval has been called on the sequence during the 
session in question.
Can you give us the trigger code?

>
> Note that this works without any trouble if I issue the commands in a
> transaction through psql, and this used to work in earlier versions of
> postgres.
>

In any case double check that the server version/JDBC version match.

> We have a lot of users on very high latency links, so it is important
> for the responsiveness of the application to try to do the update and
> select in a single database trip.
>
> So I'm wondering whether there is some type of race condition, where the
> selection of the new value from ip_audit_seq is not available to the
> currval function straight away? Anybody got any ideas on this?
>
> Cheers,
>
> Adriaan
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org

-- 
Achilleas Mantzios



view thread (11+ messages)  latest in thread

Message-ID: <200610231704.05113.achill@matrix.gatewaynet.com>
Permalink:  ../200610231704.05113.achill@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/200610231704.05113.achill@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: achill@matrix.gatewaynet.com, pgsql-jdbc@postgresql.org
  Subject: Re: currval() race condition on server?
  In-Reply-To: <200610231704.05113.achill@matrix.gatewaynet.com>
  References: <453CC859.8070306@albourne.com> <200610231704.05113.achill@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox