pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Saleem EDAH-TALLY <nmset@netcourrier.com>
To: pgsql-jdbc@postgresql.org
Subject: getGeneratedKeys
Date: Mon, 9 Mar 2009 20:20:58 +0100
Message-ID: <200903092020.58921.nmset@netcourrier.com> (raw)

Hello,

This is just a request in the hope it may help not all but 95% of devs. The 
other 5% would know by notice that they have to write their own solution; for 
now, 100% of devs have to write their own.

I have followed 
http://archives.postgresql.org//pgsql-jdbc/2004-09/msg00191.php
and
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&safe=off&threadm=Pin...
 and I understand quite well that currval is useless with multiple inserted 
rows, and the one inserted row situation with two colums having the same 
sequence as default values cannot rely on currval. I consider these situations 
to be in those 5% or less where the devs know what they are doing.

Sequences appended to columns as defaults can easily be retrieved

"SELECT column_default FROM information_schema.columns WHERE table_name = '" + 
tblName + "' AND column_default LIKE 'nextval(''%_%_seq''::regclass)'"

The driver may parse the results to get the sequence(s) name(s) and hence 
querying again to retrieve the currval(s), returning a resultset with most 
often one column and more if there are more than one column with a sequence as 
default value. If the same same sequence is found more than one time as 
default value, then the driver may generate an error as 'not implemented'.

Of course multiple inserted rows cannot be managed at all.

Concerning having more than one same sequence as default values in a table is 
quite an odd situation. Serious devs won't do that.

A table could yet have more than column with a sequence as default, and the 
returned generated keys could all be forwarded by the driver if the sequences 
are all different.

So I think the driver may provide getGeneratedKeys in a realistic approach, 
and generating errors for these very rare odd situations.

Thank you for considering.

view thread (17+ messages)  latest in thread

Message-ID: <200903092020.58921.nmset@netcourrier.com>
Permalink:  ../200903092020.58921.nmset@netcourrier.com/
Also on:    postgresql.org/message-id/200903092020.58921.nmset@netcourrier.com

 · 

reply

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-jdbc@postgresql.org
  Cc: nmset@netcourrier.com
  Subject: Re: getGeneratedKeys
  In-Reply-To: <200903092020.58921.nmset@netcourrier.com>
  References: <200903092020.58921.nmset@netcourrier.com>

* 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