From: Steven Hirsch <snhirsch@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Odd behavior with 'currval'
Date: Fri, 9 Feb 2018 12:33:46 -0500 (EST)
Message-ID: <alpine.DEB.2.20.1802091229550.5809@z87> (raw)
In-Reply-To: <a1e65e32-1e45-12c5-679c-78ea549548d4@aklaver.com>
References: <alpine.DEB.2.20.1802081050480.5809@z87>
<CA+bJJbw-V2_gCUkbFTAn5USXZ9jtHrzh9vVMbB7mwg_yrMDyvQ@mail.gmail.com>
<alpine.DEB.2.20.1802081243130.5809@z87>
<CAKFQuwYOid4vqN6abpxS=VrrYnt3PBnmvSF+Lk317cuL_jW32w@mail.gmail.com>
<alpine.DEB.2.20.1802081443480.5809@z87>
<CAKFQuwYCK1qXkmcO2e7az5ZDX=y5xBvJT-29zQNFSXuuvR1_pQ@mail.gmail.com>
<CAKFQuwaY1N6hR258U8z0qd52RR5TJvg+aGc2rfgG_OAAaQpi0Q@mail.gmail.com>
<alpine.DEB.2.20.1802081620300.5809@z87>
<CAKFQuwaLWdEp64f0RWZbM-F-fzzE_Qe3mMXH_s7THJ=TR1A9iA@mail.gmail.com>
<alpine.DEB.2.20.1802081638250.5809@z87>
<CA+bJJbwDacAxT8LsPhFfFjpO6DaR7H-XFpyJ8nukSfOXsTdkwQ@mail.gmail.com>
<alpine.DEB.2.20.1802091143470.5809@z87>
<a1e65e32-1e45-12c5-679c-78ea549548d4@aklaver.com>
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.
> "
--
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: snhirsch@gmail.com
Subject: Re: Odd behavior with 'currval'
In-Reply-To: <alpine.DEB.2.20.1802091229550.5809@z87>
References: <alpine.DEB.2.20.1802081050480.5809@z87> <CA+bJJbw-V2_gCUkbFTAn5USXZ9jtHrzh9vVMbB7mwg_yrMDyvQ@mail.gmail.com> <alpine.DEB.2.20.1802081243130.5809@z87> <CAKFQuwYOid4vqN6abpxS=VrrYnt3PBnmvSF+Lk317cuL_jW32w@mail.gmail.com> <alpine.DEB.2.20.1802081443480.5809@z87> <CAKFQuwYCK1qXkmcO2e7az5ZDX=y5xBvJT-29zQNFSXuuvR1_pQ@mail.gmail.com> <CAKFQuwaY1N6hR258U8z0qd52RR5TJvg+aGc2rfgG_OAAaQpi0Q@mail.gmail.com> <alpine.DEB.2.20.1802081620300.5809@z87> <CAKFQuwaLWdEp64f0RWZbM-F-fzzE_Qe3mMXH_s7THJ=TR1A9iA@mail.gmail.com> <alpine.DEB.2.20.1802081638250.5809@z87> <CA+bJJbwDacAxT8LsPhFfFjpO6DaR7H-XFpyJ8nukSfOXsTdkwQ@mail.gmail.com> <alpine.DEB.2.20.1802091143470.5809@z87> <a1e65e32-1e45-12c5-679c-78ea549548d4@aklaver.com> <alpine.DEB.2.20.1802091229550.5809@z87>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox