getGeneratedKeys - Mailing list pgsql-jdbc

From Saleem EDAH-TALLY
Subject getGeneratedKeys
Date
Msg-id 200903092020.58921.nmset@netcourrier.com
Whole thread Raw
Responses Re: getGeneratedKeys  (Kris Jurka <books@ejurka.com>)
List pgsql-jdbc
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=Pine.LNX.4.33.0312301523060.5331-100000@leary.csoft.net&rnum=3&prev=/groups?q=generated+keys&hl=en&lr=&ie=UTF-8&group=comp.databases.postgresql.interfaces.jdbc&c2coff=1&safe=off&selm=Pine.LNX.4.33.0312301523060.5331-100000%40leary.csoft.net&rnum=3
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.


pgsql-jdbc by date:

Previous
From: Scott Carey
Date:
Subject: Re: [PERFORM] Query much slower when run from postgres function
Next
From: Oliver Jowett
Date:
Subject: Re: [PERFORM] Query much slower when run from postgres function