pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steven Hirsch <snhirsch@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Odd behavior with 'currval'
Date: Thu, 8 Feb 2018 11:09:45 -0500 (EST)
Message-ID: <alpine.DEB.2.20.1802081050480.5809@z87> (raw)

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).

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!

-- 




view thread (37+ messages)  latest in thread

Message-ID: <alpine.DEB.2.20.1802081050480.5809@z87>
Permalink:  ../alpine.DEB.2.20.1802081050480.5809@z87/
Also on:    postgresql.org/message-id/alpine.DEB.2.20.1802081050480.5809@z87

 · 

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: snhirsch@gmail.com
  Subject: Re: Odd behavior with 'currval'
  In-Reply-To: <alpine.DEB.2.20.1802081050480.5809@z87>
  References: <alpine.DEB.2.20.1802081050480.5809@z87>

* 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