pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Steven Hirsch <snhirsch@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Odd behavior with 'currval'
Date: Thu, 8 Feb 2018 08:21:34 -0800
Message-ID: <30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1802081050480.5809@z87>
References: <alpine.DEB.2.20.1802081050480.5809@z87>

On 02/08/2018 08:09 AM, Steven Hirsch wrote:
> I have a body of code using JDBC to work with a PostgreSQL 9.6 database. 
> All tables use 'SERIAL' or 'BIGSERIAL' types to generate ids.  All are 
> working correctly in terms of using the next value as a default. 
> However, reading back the most recently applied (currval) value is 
> failing for one table, where it always returns '0'. Note that the table 
> data shows the expected value when queried by SELECT!  It is only the 
> currval() function that is wrong.  I am properly guarding for SQL 
> exceptions and none are being thrown.
> 
> The code being used in the failing case is not the slightest bit 
> different from the working cases in terms of structure and transaction 
> control - only the SQL, column count, etc. is different (but correctly 
> formed and in all other ways functional).

Can we see the table schema and the currval code?

Is there anything in the Postgres logs that might help?

> 
> I'm not sure where to start debugging this.  Can anyone give me even a 
> working theory to explain how returning a bogus value is possible?  When 
> I look at the sequences in pgAdmin, they are as expected in terms of 
> ownership, etc.  And, again, the table IS getting the correct value.
> 
> Thanks much for any ideas!
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (37+ messages)  latest in thread

Message-ID: <30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.com>
Permalink:  ../30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.com/
Also on:    postgresql.org/message-id/30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.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-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, snhirsch@gmail.com
  Subject: Re: Odd behavior with 'currval'
  In-Reply-To: <30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.com>
  References: <alpine.DEB.2.20.1802081050480.5809@z87> <30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.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