Re: INSERT and get ID - Mailing list pgsql-jdbc

From Sebastiaan van Erk
Subject Re: INSERT and get ID
Date
Msg-id 42E79710.2050509@sebster.com
Whole thread Raw
In response to Re: INSERT and get ID  (Roland Walter <rwa@mosaic-ag.com>)
List pgsql-jdbc
If you're going to do an extra select anyway, I would do it *before* the
insert. Select the nextval from the sequence and use that as the primary
key for the insert.

Greetings,
Sebastiaan

Roland Walter wrote:
> Peter.Zoche@materna.de schrieb:
>
>>> You have to do a a "SELECT curval('myseq')" after the insert.
>>
>>
>>
>> I had this in mind, too, but I am not sure if it is really safe if
>> there are several inserts at the same time...
>>
>
> What do you mean with at the same time?
>
> Different connections see different sequence values. So there is no
> need to worry.
>
> If you did the
> insertions within the same connection, you have to ask the current value
> of the sequence after each INSERT.
>
>

pgsql-jdbc by date:

Previous
From: "Rohit Ankushe"
Date:
Subject: JDBC JAR Problem
Next
From: "Xavier Poinsard"
Date:
Subject: Re: JDBC JAR Problem