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 1ejoxG-0002pG-Al for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 16:21:46 +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 1ejoxF-0003Sc-EA for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 16:21:45 +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 1ejoxE-0003SQ-LL for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 16:21:45 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ejox7-00030J-O6 for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 16:21:43 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 9582320F38; Thu, 8 Feb 2018 11:21:35 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Thu, 08 Feb 2018 11:21:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=zedmb0j/qzPwrkOuhrUAqJji7yM47 kC57ixq02nyuhE=; b=AHaNysqZhiCg8sj8MuK9+IwYdFJ0RpTfyexp8m9dvgRoG fLfDDJbTTEuV5untMXLuiKUJzgrH2xfO7AMcac+kff6win3b/vBD/bdnMkrLH+Ej QnOhlnSr/pgpRpq/gn1OvKTcn9u+pCwjhg7lvCTrK+t2s4JC/A+j/lFkxGs4krBf KGzaqYiTFYMarg/JqcaKXLbeguAEIj3wK+l5RNOoreYk4lOdXssCQRFN5oou9gMD u10KtTrT8G/5vL6A6oVkHeGqeiZKZ1QOJ+EBn1HgEUttgBk7w7gSSsdM+Hb2D83a V1RrEVE3cvX4VMzWN06zjr3WQDdnSx2PYkdyyqXDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=zedmb0 j/qzPwrkOuhrUAqJji7yM47kC57ixq02nyuhE=; b=O5Z5aspK/A16HGVe70EfKg 3pU+jNi+vQhmpjdL7IyPzpdWC5b9naWDHpxhNgiRSTcw8hCnECPfNl1hC5GZmuDz j3c9bVjtACLMPD8C98YX8KxSw3eCq6q0UWrwXESSsbZUhL0Cs7TRddiKaahy0xhr pe1Es20FmfeI8RrauAMZR6YBne7GDsEZLFhW09Z2FD8/KBMy4HRB+N0clhcHNNaY rH70p8KRKko5lRT787kddznmisj39YBFUF77Rva77W60YGxk/PxGW+mdmZ7F0C3t HKRtsPanL18zSB9pv+xeFmwDz7W7yVG1ReKFInTsNh0/mR3Hp4i0leWI9kTuyxZQ == X-ME-Sender: Received: from ranger.suse (71-212-36-41.tukw.qwest.net [71.212.36.41]) by mail.messagingengine.com (Postfix) with ESMTPA id 08FCC7E576; Thu, 8 Feb 2018 11:21:34 -0500 (EST) Subject: Re: Odd behavior with 'currval' To: Steven Hirsch , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <30b1c4e7-b576-8ed2-b7c9-44f59c20558d@aklaver.com> Date: Thu, 8 Feb 2018 08:21:34 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/08/2018 08:09 AM, Steven Hirsch wrote: > 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). Can we see the table schema and the currval code? Is there anything in the Postgres logs that might help? > > 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! > -- Adrian Klaver adrian.klaver@aklaver.com