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 1ejolk-0001y9-QK for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 16:09:52 +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 1ejolj-0000ps-Tw for pgsql-general@arkaria.postgresql.org; Thu, 08 Feb 2018 16:09:51 +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 1ejolj-0000ph-Lu for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 16:09:51 +0000 Received: from mail-qt0-x22e.google.com ([2607:f8b0:400d:c0d::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ejolg-000678-UX for pgsql-general@lists.postgresql.org; Thu, 08 Feb 2018 16:09:51 +0000 Received: by mail-qt0-x22e.google.com with SMTP id d8so6828278qtm.0 for ; Thu, 08 Feb 2018 08:09:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:user-agent:mime-version; bh=Qzt7z0Z3bX9YSEVtKdRuYl2Hl/0X6xjgmGrbEx6LccY=; b=cBk8s7S44rdJypvEDFlsiLT8ASKHUvt9gVVPeyPwKa4hVFTaOgvW594tw6+U1oJ1KT gtTiFcKJNrvRmOxNHVdfCKq3+tRf0aOAlKvLsXGnsdrxi9s9gX1ndm/GJrsM6kVQ+D16 DUXLx1xebpo4E5glfYQLKbt5CZhB0p5FKFB0IoHo83QEkqY+75a0iyZxYgk5xtKlPP5H c5YlYQqJ5oOao1Ad82C4kh1RPLKiOH7bjIs9AgbUnUf7JEPb4mcaB0cHSLHU1+5+m4ei hWUyew7YkGbg/6YQi4sPPOZdgviDIDO2GYBSaiuKSet9pV6kqz1pLUo+FOhd+jlXAhIh NcVA== 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:message-id:user-agent :mime-version; bh=Qzt7z0Z3bX9YSEVtKdRuYl2Hl/0X6xjgmGrbEx6LccY=; b=Gc6FbURGjVWhypSpqTvzt3GIbFYruDM5uNDsJjKhcDJ1OaGCJH/zfHVqGNhlVyXzA3 zGVEvT58DjYq9RtNMMAj+HEBkyIfDmwYCEZQYQKzp3KHse3TvN53ujvdKPU7XC2RMSYb TRIhqvqBYf4rz/qwd4g4G8ISbAka8cVKeqLouC7EzWeL083ByNieJaXMzKu8uBybli52 M8cN2PRNQ+h8KK2y6jtU85DLd4dwfYf24mpSK92J9Vzqwv1afJIYjRYSQF0cxTsPA26Z z7GBZFNj+7Kn+KJroYbzdBvpca4S9I1iYTlxboZyjGnkCViYCI1+bYQ6s9xWG3Z9paeu ZHjA== X-Gm-Message-State: APf1xPC/WMGhs56YT0qj1loKgMzqMVcG0PTsbxp/lNOpxx7x7VkGyTCN kBX8qV1p7If7QjLZ1A0/5PTGrw== X-Google-Smtp-Source: AH8x226SaeIWoJQm22qeuCLHIkl94dv+/Puu7VWO7EVJIt8gYbi/3S7BPQEeG+VWU8T0yx+kbfcoNQ== X-Received: by 10.200.97.13 with SMTP id a13mr1865875qtm.16.1518106186568; Thu, 08 Feb 2018 08:09:46 -0800 (PST) Received: from [192.168.245.27] ([65.183.149.206]) by smtp.gmail.com with ESMTPSA id e39sm213765qtb.6.2018.02.08.08.09.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Feb 2018 08:09:45 -0800 (PST) Date: Thu, 8 Feb 2018 11:09:45 -0500 (EST) From: Steven Hirsch X-X-Sender: hirsch@z87 To: pgsql-general@lists.postgresql.org Subject: Odd behavior with 'currval' Message-ID: 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 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). 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! --