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 1ekAu5-0001Zu-3B for pgsql-general@arkaria.postgresql.org; Fri, 09 Feb 2018 15:47:57 +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 1ekAu4-00034s-7f for pgsql-general@arkaria.postgresql.org; Fri, 09 Feb 2018 15:47:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekAu3-00034i-T5 for pgsql-general@lists.postgresql.org; Fri, 09 Feb 2018 15:47:56 +0000 Received: from mail-qk0-x22c.google.com ([2607:f8b0:400d:c09::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ekAu1-0008Ho-7C for pgsql-general@lists.postgresql.org; Fri, 09 Feb 2018 15:47:54 +0000 Received: by mail-qk0-x22c.google.com with SMTP id m130so10496069qke.1 for ; Fri, 09 Feb 2018 07:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peoplecall-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=EP/z4vdfusd4+4lVPe4zgLYZFRwVNr4MLYcI5TghAD4=; b=AQReJcfhrqHwQn8S8TELYqr1v/IrKmpXoR3U1HTMidwc68nfEPRV2KYl0w8pWPss4l ZIgMRJPvKblWaAj4E8NUb21jujHVppWcYCSzZo8Rb48VmMlDNlRLd2UP6KdkI+AdYmVs AP+EGgUCnfGNdRTIBpw4fPp2J3MTLKNXi8t3GpeEEWXDGIxDNCc++dVMQO6oXPOPlUE9 ZcF04z3MrGYqvyFuOXdmAXgyS8V6EJ4Izfv9aEQmZjIh7qSsAPtA9TioIfLBFl08OGRy nwHxnEX1iqLtZIfNboYD7K/AzMHfchJcpfS+qtHs+n3I8hLRLdmEdVDzpAkJb+LvdNtH ejvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=EP/z4vdfusd4+4lVPe4zgLYZFRwVNr4MLYcI5TghAD4=; b=ey6YUNaxUpCXZzkOtyMz/NxuN+FrF5vpHybFMmfGYqp+daf+jUUGKhZEYUWGeckEQp XMUdu/L/RbGj1ZHa5CITsSvs8sk2v46EksrwsY3E0mYBFWvQ4QGzWt67TOR+eWXX5jV5 97HJ8lKbWD/WHfIAHPtvZXi7XNiRn8l0ZhOnOreYRtWUeqYUJLZO2kCOIn8l3B0F94ES 09bIFGCEJRBme5FVrE0VkokZjIY8KfxDN6IXN/eLSHsPjpFWd7/0L2eUPfooOq+nr+EY e0fcISASF+Pfx97BkOdwTP2lr0JsmTObxWCO7SY34hyX1G/KTSS8HaqmSeVXZx1JBO3b 8Jew== X-Gm-Message-State: APf1xPBwEZmV8UthQJ9hPYUUVh4MXjaKQEpqPK50dc7hVq17Zw/NvJSM Ugbnf4twJVdsXO0WKuyeXYBzJ/9r7t/7fc0G0ha6yw== X-Google-Smtp-Source: AH8x227V9Vnw1DFn/oCU2WE8IymN/9fQLzkkYR9KI7j9+m1gS7hqMmRzND9WEigDV8+TxVo23S2dNl5Q2AHqIPzOvK8= X-Received: by 10.55.4.135 with SMTP id 129mr1199460qke.89.1518191271938; Fri, 09 Feb 2018 07:47:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.52.131 with HTTP; Fri, 9 Feb 2018 07:47:10 -0800 (PST) In-Reply-To: References: From: Francisco Olarte Date: Fri, 9 Feb 2018 16:47:10 +0100 Message-ID: Subject: Re: Odd behavior with 'currval' To: Steven Hirsch Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Steven: On Thu, Feb 8, 2018 at 10:52 PM, Steven Hirsch wrote: This may sound a bit harsh but: > 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. No, that's not a JDBC problem, that's pilot error. JDBC has behaved like these for ever, and you have had people chasing ghosts ( not a biggie, we are used to this ) because, instead of providing the real chunks you were running you kept saying "when I select currval() I get 0" and similar things. If you had said "when I do rs.getLong(col) I get 0", or pasted a relevant chunk of code, lots of people here would have pointed that getLong returns a primitive java long, so rs.getObject() is needed if you may get null. JDBC has been doing this forever, and they probably do it because in many cases this behaviour is useful. This also raises suspicions about your sequence ownership problems, as you may have being ( with your best intention ) pasting your code to reproduce the problems instead of the real scripts from the database. In general, when you run a code chunk for problem reporting, try to do it with psql ( which everybody has and knows how it works ) and paste the code / result directly, without much editing. This aids a lot. In fact, if you do it you may have noticed your text in psql returned an empty column in currval(null), which, knowgin it is int, means it was null ( in a string you cannot easily distinguish empty from nulls in a simple select ). Anyway, you report was quite nice and showed you put quite a bit of work in it, treat these as tips to make problem reporting / solving easier, not just as criticism. Francisco Olarte.