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 1ekC0M-0005VC-Ex for pgsql-general@arkaria.postgresql.org; Fri, 09 Feb 2018 16:58:30 +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 1ekC0L-00083J-BA for pgsql-general@arkaria.postgresql.org; Fri, 09 Feb 2018 16:58:29 +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 1ekC0K-000839-U6 for pgsql-general@lists.postgresql.org; Fri, 09 Feb 2018 16:58:29 +0000 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ekC0I-0001OO-EJ for pgsql-general@lists.postgresql.org; Fri, 09 Feb 2018 16:58:27 +0000 Received: by mail-qt0-x243.google.com with SMTP id d26so889991qtk.10 for ; Fri, 09 Feb 2018 08:58:26 -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=uTnIzwPaWhcag0ozH33TTB5sLo9OE/tY25iAv3hJJfk=; b=naA47B7JeOt3tt2fFBbmbbAI5ts1NF7o/k1uM6ZbNGFZ+Hw6dOy7n5Y31cgzs+J6f9 rqkYjX/5fA/gBfNcisTRwB5N87XdBsORYq5CeXMy4RUhhsGHWnAW5cp85Tciwbwa0sbC TFcuKo4+ELazm6fzhS86ynHfoaaZWARkjcG7Fy+9DPCHJho9omsCD8uin6GfGSM9EOHz TYAIt7dIxy41qk5yNhCAELN8Lho0GWPstgWVQHgz7xcNzgQ36uJbHjp1lFpzdJfZ6JJw 6VtsWzY2tZcjmmjruYdzXh8UUApnaj4ZdkQhCE8mPi4QAlthLf4hOU6bJLHpxwH+K178 ULyQ== 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=uTnIzwPaWhcag0ozH33TTB5sLo9OE/tY25iAv3hJJfk=; b=hmX7S6LxLQlyyQJ9ksQI5x3YATswAGlABzPOISIEvHeb13oI/0uWoW7hS1tVX9NxRp V/r7tWgnHodskz/vodOUdB5cNuZ5E2KeB7d7+3lIjeikUHXw8HoWrqpY9VHA7XywjIRI n+nNv0d17abTsQb+YsfyHs5dQiXlWGi8APYFnbR4Zxh4Y1PlfxV1GmLutYwEljPLi9kV 6HemdoS0hvLMWZucgiyHPYiG+rRuJltpxNAKxDY2bqL/j4bxsWuEGZtVhS0KpSETWGFw SHyJjy2ldIT4XBvN7A77HPRhib06WAQNZ8WIw+CycPnBRCcV6ohaiIj4UxV65WPIJDk5 5EKg== X-Gm-Message-State: APf1xPAyAbkhtAVtI7UWPiaTTqBgC6MQyefbeKbsZXMGXl2nzV559lAT 9/rQVZx3y3FNMnZbFz8wlKJrig== X-Google-Smtp-Source: AH8x22600eeTFQPegyhg7NNSBJGx6PspKP9twRX6KzOxt3EDROFBkFP2QivsZZG23r81qP4W6BbzUA== X-Received: by 10.200.52.59 with SMTP id u56mr5347896qtb.225.1518195504808; Fri, 09 Feb 2018 08:58:24 -0800 (PST) Received: from [192.168.245.27] ([65.183.149.206]) by smtp.gmail.com with ESMTPSA id d36sm2274785qtf.15.2018.02.09.08.58.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 08:58:24 -0800 (PST) Date: Fri, 9 Feb 2018 11:58:23 -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: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 9 Feb 2018, Francisco Olarte 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. Of course it is, but that doesn't change the fact that the behavior of JDBC is not helpful at all. It also doesn't change the fact that I had a very real and very confusing "disconnect" between the sequence and the table. That may well have been pilot error on my part, but was extremely subtle and unusual in its impact - as witnessed by the number of rounds we went before David hit the issue with ownership. > 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. Please note that I _did_ post the JDBC code after being requested to do so. It showed clearly where I was using rs.getLong() to retrieve the id. No one commented on that as being a factor. Given Java's usual strictness about converting null to numerics, I do not find it useful. I find it completely broken and orthogonal to the spirit of a type-safe language. In my opinion, this: long i = rs.getLong(n); should throw a type exception if NULL is fetched and this: Long i = rs.getLong(n); should give 'i' the value of 'null'. Getting 0 as an answer simply makes no sense at all to me. But, now that I've been burned by it, I'll certainly never make the same mistake again. I'll make other mistakes :-). > 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. Not following this statement. After being requested to do so, I did post the actual JDBC code. Did that not show up in the message thread? Nothing was done to edit down or elide anything. > 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 ). Of course I noticed it! That's how I finally spotted the issue. If I was a bit more on the ball, I'd have used psql from the start. So, now that I understand the importance of doing so (and the brain-dead behavior of JDBC) I will be sure to do so in the future. > 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. I do not take your tone as harsh. I'm willing to take responsibility where I created my own problems. I have learned that I must reduce trouble reports to issues that can be reproduced in psql. It makes sense and I'll do so in the future. --