Re: Synthesize support for Statement.getGeneratedKeys()?

From: Ken Johanson <pg-user(at)kensystem(dot)com>
To: Dave Cramer <pg(at)fastcrypt(dot)com>
Cc: Michael Paesold <mpaesold(at)gmx(dot)at>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Synthesize support for Statement.getGeneratedKeys()?
Date: 2007-01-21 19:06:51
Message-ID: 45B3B9CB.3070308@kensystem.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Dave Cramer wrote:
>>
>> 3) Is there a) an efficient RETURNING clause to pre-populate the
>> generated-keys result set, or b) should I synthesize it.
>
> I take it from this that you are intending on returning all generated
> columns?, just generated columns that have keys ?
>>

Yes, ideally. I'd prefer not to try and synthesize the values from only
a single (last or first row's) key, since sequences can have increment
values other than one, and because OIDs are not predictable (are they?).
Other server generated key types also seem to make the synthetic idea
unfeasible.

>> 4) If 3b is required, then besides incrementing (by one) sequences,
>> any suggestions on how to correctly synthesize other increment values?
>> Other key types (OIDs, etc?)
>
> Are you suggesting here that you are planning on incrementing the
> sequences by 1 ? Why not just let the insert occur and get the currval
> of the sequence ?

I'm thinking what you're thinking; get the current value; however the
increment I mention is just in case I cant get more than one curval... I
don't know, can I get 3 values from RETURN if I insert three VALUEs in
one query??

>>
>> 5) To be absolutely sure, inserting multiple values then getting the
>> sequence back (RETURNING) will happen atomically in the server, correct?
>> (to avoid getting another transaction's keys).
> You don't want to return the sequence, as it can be changed by another
> transaction, you want to return the value in the row that was inserted.
>>

Agreed.

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2007-01-22 00:21:38 Re: Synthesize support for Statement.getGeneratedKeys()?
Previous Message Kris Jurka 2007-01-21 05:10:09 Re: Max size for bytea type