Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eju75-0007UW-TZ for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 21:52:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eju74-0002tJ-CN for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 21:52:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eju74-0002tA-2S for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 21:52:14 +0000 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eju70-0005Uw-Ol for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 21:52:13 +0000 Received: by mail-qk0-x241.google.com with SMTP id c82so7601083qka.0 for ; Thu, 08 Feb 2018 13:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:in-reply-to:message-id:references:user-agent :mime-version; bh=ccTwLAIZ7Z6+TjlBbC7Yxoq6k7pPXSm6RYG1KQ4rw+c=; b=B2fjsYlhfMkmuINX9FpyAruVO49tu2vp5mhurJTmub8jFVfhOC3Rt3banU4Ouce9VB 0Us2nnUeIn0JpXMNiLkdRVeHAYLtOUm/Rx3JdwCi0cNXKL7SrvluGx33A8hOD+iglvjP HLFHFDwodfx0nsV1dSXRDzC1VcSacAfB8M4vvKg3Ce2wCkX1B8yZRtOJdsyXyScUUP/x 20acrawmfisRwqECsllfLi27j7QsVPDUJJfsIixvB16QbVe16v/1EncMRc68oYKULkb5 mIZm6IXXUOjmpJW83FKamvmDOZOnZBAy5W/PPZnURHp815aQvaWVL8Q0K3bsS7DMicV7 aiIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=ccTwLAIZ7Z6+TjlBbC7Yxoq6k7pPXSm6RYG1KQ4rw+c=; b=GcjlZMxBf8LkfGNAOpa2w6VMzlRqt4gY1b/92xFER2ezXQ+oWMPTjMSgz/KPUast62 JWuccKk5GnQJp3nhRLmFaf2ReJD+sTYX0krpVXjeYSTMSQ4+6YxZR6rCLk9eSXzlKPhQ 9n+cANj1jqIYVT9V+0I2FQAmMr/bd1xg58isUhAFaO14/r81Gpmp61uPJQ1Dg8xrZ36p 8uBF9iibVQ1XCI3XSgmui/jfEMonlz+KxHgRXtEKmLwqGvIqG5KhKE7LbOBtg8uOM+Ya guB461dx+8OQSf4FSIzdVWeS0Enk7iSXp/fDt3ZMk8V/gOQ65YK2QjNtUI/EIga7g7XT flIg== X-Gm-Message-State: APf1xPBvnPX1LaSpLRUOuOLlKhU9840aMfr6/ljtaxMevAEsSV/2A+WG /SMndWNMxJqfVyJmHp1Jj0h4rw== X-Google-Smtp-Source: AH8x227kQrqeMVvMHVI7F3CklYPWCLTRWskz3XpQZFz0YPNosV4/Wq8eVqQ83j1cB1H9IswLrVKXNA== X-Received: by 10.55.8.146 with SMTP id 140mr748680qki.169.1518126728903; Thu, 08 Feb 2018 13:52:08 -0800 (PST) Received: from [192.168.245.27] ([65.183.149.206]) by smtp.gmail.com with ESMTPSA id n36sm760719qta.5.2018.02.08.13.52.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 13:52:08 -0800 (PST) Date: Thu, 8 Feb 2018 16:52:07 -0500 (EST) From: Steven Hirsch X-X-Sender: hirsch@z87 To: pgsql-general@lists.postgresql.org Subject: Re: Odd behavior with 'currval' In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-2098838891-1518126728=:5809" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-2098838891-1518126728=:5809 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT 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. -- --8323329-2098838891-1518126728=:5809--