Re: INSERT and get ID

From: Sebastiaan van Erk <sebster(at)sebster(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: INSERT and get ID
Date: 2005-07-27 14:15:44
Message-ID: 42E79710.2050509@sebster.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)Zoche(at)materna(dot)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.
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Xavier Poinsard 2005-07-27 14:37:46 Re: JDBC JAR Problem
Previous Message Roland Walter 2005-07-27 13:53:01 Re: INSERT and get ID