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: Re: Odd behavior with 'currval'
Date: Thu, 8 Feb 2018 16:52:07 -0500 (EST)
Message-ID: <alpine.DEB.2.20.1802081638250.5809@z87> (raw)
In-Reply-To: <CAKFQuwaLWdEp64f0RWZbM-F-fzzE_Qe3mMXH_s7THJ=TR1A9iA@mail.gmail.com>
References: <alpine.DEB.2.20.1802081050480.5809@z87>
	<CA+bJJbw-V2_gCUkbFTAn5USXZ9jtHrzh9vVMbB7mwg_yrMDyvQ@mail.gmail.com>
	<alpine.DEB.2.20.1802081243130.5809@z87>
	<CAKFQuwYOid4vqN6abpxS=VrrYnt3PBnmvSF+Lk317cuL_jW32w@mail.gmail.com>
	<alpine.DEB.2.20.1802081443480.5809@z87>
	<CAKFQuwYCK1qXkmcO2e7az5ZDX=y5xBvJT-29zQNFSXuuvR1_pQ@mail.gmail.com>
	<CAKFQuwaY1N6hR258U8z0qd52RR5TJvg+aGc2rfgG_OAAaQpi0Q@mail.gmail.com>
	<alpine.DEB.2.20.1802081620300.5809@z87>
	<CAKFQuwaLWdEp64f0RWZbM-F-fzzE_Qe3mMXH_s7THJ=TR1A9iA@mail.gmail.com>

On Thu, 8 Feb 2018, David G. Johnston wrote:

new_db=# \dfS+ currval

List of functions
    Schema   |  Name   | Result data type | Argument data types |  Type  | 
Volatility | Parallel |  Owner   | Security | Access privileges | Language 
| Source code |      Des
cription
------------+---------+------------------+---------------------+--------+------------+----------+----------+----------+-------------------+----------+-------------+---------
---------------
  pg_catalog | currval | bigint           | regclass            | normal | 
volatile   | unsafe   | postgres | invoker  |                   | internal 
| currval_oid | sequence
  current value
(1 row)

> I'll agree this would be highly unusual but I so would this being a 
> bug.  And the oddity with the lost sequence ownership...

So, I believe I have gotten to the bottom of the issue.  Your suggestion 
to stay within psql was the secret.  Not too surprisingly, when I run:

--- code ----

\pset null '(null)'

CREATE TABLE bugtest (
   id BIGSERIAL NOT NULL,
   name VARCHAR(32) NOT NULL,
   PRIMARY KEY (id)
);

INSERT INTO bugtest(name)
VALUES ('one');

SELECT currval( pg_get_serial_sequence('bugtest','id'));

INSERT INTO bugtest(name)
VALUES ('two');

SELECT currval( pg_get_serial_sequence('bugtest','id'));

ALTER SEQUENCE bugtest_id_seq
OWNED BY NONE;

INSERT INTO bugtest(name)
VALUES ('three');

SELECT currval( pg_get_serial_sequence('bugtest','id'));

--- end code ---

I see:

--- output ---

Null display is "(null)".
CREATE TABLE
INSERT 0 1
  currval
---------
        1
(1 row)

INSERT 0 1
  currval
---------
        2
(1 row)

ALTER SEQUENCE
INSERT 0 1
  currval
---------
   (null)  <---- !!!!
(1 row)

-- end output ---

The culprit is in the JDBC domain, NOT PostgreSQL!  According to the 
documentation I found, the ResultSet 'getLong()' method returns a value of 
zero when it sees NULL as an input. Why the JDBC libs don't treat this as 
an invalid numeric conversion is beyond me.

Once again, thanks to everyone who took their time to help me out on this 
issue.  It's a great reminder of the high-quality community that surrounds 
PostgreSQL.



-- 

view thread (37+ messages)  latest in thread

Message-ID: <alpine.DEB.2.20.1802081638250.5809@z87>
Permalink:  ../alpine.DEB.2.20.1802081638250.5809@z87/
Also on:    postgresql.org/message-id/alpine.DEB.2.20.1802081638250.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.1802081638250.5809@z87>
  References: <alpine.DEB.2.20.1802081050480.5809@z87> <CA+bJJbw-V2_gCUkbFTAn5USXZ9jtHrzh9vVMbB7mwg_yrMDyvQ@mail.gmail.com> <alpine.DEB.2.20.1802081243130.5809@z87> <CAKFQuwYOid4vqN6abpxS=VrrYnt3PBnmvSF+Lk317cuL_jW32w@mail.gmail.com> <alpine.DEB.2.20.1802081443480.5809@z87> <CAKFQuwYCK1qXkmcO2e7az5ZDX=y5xBvJT-29zQNFSXuuvR1_pQ@mail.gmail.com> <CAKFQuwaY1N6hR258U8z0qd52RR5TJvg+aGc2rfgG_OAAaQpi0Q@mail.gmail.com> <alpine.DEB.2.20.1802081620300.5809@z87> <CAKFQuwaLWdEp64f0RWZbM-F-fzzE_Qe3mMXH_s7THJ=TR1A9iA@mail.gmail.com> <alpine.DEB.2.20.1802081638250.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