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 1ekCYg-0007XJ-T6 for pgsql-general@arkaria.postgresql.org; Fri, 09 Feb 2018 17:33:59 +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 1ekCYd-0002B5-TW for pgsql-general@arkaria.postgresql.org; Fri, 09 Feb 2018 17:33:55 +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 1ekCYd-0002Aw-HQ for pgsql-general@lists.postgresql.org; Fri, 09 Feb 2018 17:33:55 +0000 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ekCYW-000275-UV for pgsql-general@lists.postgresql.org; Fri, 09 Feb 2018 17:33:54 +0000 Received: by mail-qk0-x242.google.com with SMTP id n188so10917655qkn.11 for ; Fri, 09 Feb 2018 09:33:48 -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=Th6kdKzuzf0aD1VvhDN2xqikLr08YB1dFmHkH4qDpX0=; b=mTSJjThjVf6n4p5rp7M5LEy8Qi6saCs7Fg/ogm/Q102ZuGSdxIq4BbD5ro0qAcbk2N gieBI5EPmA+XkmqiP9Z8bEx0A++Whr0ybDz3+YOB+raMdUmb5bmJlIVJt+u8tPeB9Vpm r6B+TtaVnnIFxQ6RIy49Q9UZ566cpjV7LPcdJCoWxMYXDegIK/gLvKRRLxymDAcADVEA yUyoyvpWgwo74sDnfNnWPQRrD6KWhQPsmtkVTjIapPNktPO7D6mQRq1GvTIiOLujqhw6 KlG6zduhkaOneeUT1MYyNpkw/WEBqkF8lnplWKj5Oe+VM63qhDEJk3qv6n35+vl1avU8 hFbA== 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=Th6kdKzuzf0aD1VvhDN2xqikLr08YB1dFmHkH4qDpX0=; b=DJDdbqb7xLGcRgWxBSEUYvE6+zQNYaBzfGkG5HgYrkcdutUHZvRJKP/hrAa9974q1v ++jGFcSFcvCsEa61E+Qjdj7HJ6RC3WveZAH/Ycz0TV+mqpdMdL/VQynPI6exYa45Bnv1 vFR/EKQHgfUWY/kbgeu6014nFVedIs2NcjF65nZAdyvGb5Etz0saQIBVFj9byjSKbAy3 i+ZXOtWZqR7oDSeKIwavZ5AxI+aVrcGEkoYZy7+LGeX/sPgwom30lMTZ2dWxXGFxzZok Bc8TEqTlruxs2L3E35DyOumr4eH8bvgu4FdtiagcaEgbgxV9FQ4SVFAP6KzZYrTcCLzl sPMA== X-Gm-Message-State: APf1xPBNjXUcZ/QKJMp8b4sf0e2mOwtecAtegSo3Im4syASqXe+VhTet Dj/h1/a7iYDx3I0viUhH7p4SXQ== X-Google-Smtp-Source: AH8x226Q4IAE0bPxGLpuvugx0K3pCPi972oNuPzIXdou9gm5xUsocLure6wFeHObvOJCIPGg2+EFnA== X-Received: by 10.55.33.129 with SMTP id f1mr4731905qki.158.1518197627535; Fri, 09 Feb 2018 09:33:47 -0800 (PST) Received: from [192.168.245.27] ([65.183.149.206]) by smtp.gmail.com with ESMTPSA id v185sm2012520qkd.44.2018.02.09.09.33.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 09:33:46 -0800 (PST) Date: Fri, 9 Feb 2018 12:33:46 -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; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 9 Feb 2018, Adrian Klaver wrote: > I remember seeing it, so I went back to look at the message. Turns out you > sent it to me only. Unfortunately I am not a Java programmer so I did not > catch the error. For the record: Ah, blast... Apologies to everyone concerned. I need to understand why my mail reader (Alpine on Linux) insists on defaulting to the original poster's e-mail address when I hit 'Reply' rather than the group list. It's not doing that with any other mail list I subscribe to. I was trying to be careful and changed the address manually for all messages except this one. Thanks, Adrian! I was sure that I sent it - just not to the right place as it turns out. > " > Here is the JDBC code: > > try { > conn.setAutoCommit(false); > PreparedStatement sth = null; > ResultSet rs = null; > > // Insert new > sth = conn.prepareStatement(addAssetType); > sth.setString(1, name); > sth.execute(); > > sth = conn.prepareStatement(lastTypeId); > rs = sth.executeQuery(); > if (rs.next()) { > long id = rs.getLong(1); > result.put("id", id); > result.put("name", name); > } > else { > throw new WebApplicationException(buildError(BAD_REQUEST, > "Lookup of most recent sequence failed")); > } > conn.commit(); > } > catch (SQLException e) { > conn.rollback(); > throw new WebApplicationException(buildError(BAD_REQUEST, > e.getMessage())); > } > > > Where: > > private final static String addAssetType = > "INSERT INTO udm_asset_type_definition (def_name) " > + "VALUES (?)"; > > private final static String lastTypeId = "SELECT currval( > pg_get_serial_sequence('udm_asset_type_definition', 'def_id'))"; > > Code with this exact same structure (but different SQL, obviously) is working > just fine with five other tables using sequences. The above code snippet > always produces '0' for the id. If I use the 'INSERT .. RETURNING..' > approach, it gives the right answer. > " --