Lists: | pgsql-jdbc |
---|
From: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Support of getting generated keys in driver version 8.4devel |
Date: | 2008-12-31 12:19:23 |
Message-ID: | 802b0da7-3575-46ea-bf26-8ecc5eb50fef@p2g2000prf.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Hello!
This is my environment:
Driver version: PostgreSQL 8.4devel JDBC3 (build 700)
PostgreSQL version: 8.3.4
I am looking for getting generated keys support in the driver. The
changelog says it has basic generated keys support. However,
DatabaseMetaData.supportsGetGeneratedKeys() returns false and when I
execute:
con.prepareStatement("insert into tab0 values(default, 444)", new
String[] {"id"});
I am receiving:
Caused by: org.postgresql.util.PSQLException: Returning autogenerated
keys is not supported.
at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareStatement
(AbstractJdbc3Connection.java:448)
Am I missing something? If not, is the generated keys support going to
be implemented in a future build of 8.4devel?
Happy New Year,
Milosz
From: | Kris Jurka <books(at)ejurka(dot)com> |
---|---|
To: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2008-12-31 19:29:51 |
Message-ID: | Pine.BSO.4.64.0812311423300.10458@leary.csoft.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
On Wed, 31 Dec 2008, Mi³osz Tylenda wrote:
> I am looking for getting generated keys support in the driver. The
> changelog says it has basic generated keys support. However,
> DatabaseMetaData.supportsGetGeneratedKeys() returns false
I intentionally left supportsGetGeneratedKeys false because we don't
support returning generated keys by column indexes. Without knowing how
used that method is, I'm not sure if this is more or less helpful. I'm
open to input if people think we should change it to true.
> and when I execute:
>
> con.prepareStatement("insert into tab0 values(default, 444)", new
> String[] {"id"});
>
> I am receiving:
>
> Caused by: org.postgresql.util.PSQLException: Returning autogenerated
> keys is not supported.
This was an oversight on my part. I added support for the Statement
methods, but somehow not for PreparedStatement methods. Shouldn't be too
tough to add, let me take a look and get back to you in a day or two.
Kris Jurka
From: | Cromax <hataraku(at)wp(dot)pl> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Cc: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2008-12-31 21:56:21 |
Message-ID: | 495BEA85.2010201@wp.pl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
AFAIK it is still not implemented however, you may try to use RETURNS
clause in INSERT statement.
This works perfectly good.
Tomisław Kityński
Miłosz Tylenda pisze:
> Hello!
>
> This is my environment:
> Driver version: PostgreSQL 8.4devel JDBC3 (build 700)
> PostgreSQL version: 8.3.4
>
> I am looking for getting generated keys support in the driver. The
> changelog says it has basic generated keys support. However,
> DatabaseMetaData.supportsGetGeneratedKeys() returns false and when I
> execute:
>
> con.prepareStatement("insert into tab0 values(default, 444)", new
> String[] {"id"});
>
> I am receiving:
>
> Caused by: org.postgresql.util.PSQLException: Returning autogenerated
> keys is not supported.
> at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareStatement
> (AbstractJdbc3Connection.java:448)
>
> Am I missing something? If not, is the generated keys support going to
> be implemented in a future build of 8.4devel?
>
> Happy New Year,
> Milosz
>
>
From: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2009-01-05 09:30:11 |
Message-ID: | 35a0a1a4-cb6e-491c-9a34-39c942bbb814@z27g2000prd.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
> I intentionally left supportsGetGeneratedKeys false because we don't
> support returning generated keys by column indexes. Without knowing how
> used that method is, I'm not sure if this is more or less helpful. I'm
> open to input if people think we should change it to true.
Kris, my picture is that I work with Apache OpenJPA - an object-
relational mapper. OpenJPA checks whether generated keys are supported
by calling DatabaseMetaData.supportsGetGeneratedKeys(). If true, the
generated keys are retrieved from PreparedStatement by giving column
names. If false, a second query is executed to get the value of
sequence associated with serial column. So, in the OpenJPA context,
supportsGetGeneratedKeys returning true would be more helpful, but I
can also imagine a case where it would break things.
Greetings,
Milosz
From: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2009-01-05 09:39:18 |
Message-ID: | 472be2d5-bd00-4721-aeb1-3f70989e066d@s9g2000prg.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
> AFAIK it is still not implemented however, you may try to use RETURNS
> clause in INSERT statement.
> This works perfectly good.
> Tomisław Kityński
Tomisław, thanks. I have also tried this and it works. However, I am
more interested in driver support for generated keys because modifying
INSERT statements is not a piece of cake in my case.
Cheers,
Miłosz
From: | Kris Jurka <books(at)ejurka(dot)com> |
---|---|
To: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2009-01-15 04:29:04 |
Message-ID: | Pine.BSO.4.64.0901142323100.32378@leary.csoft.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
On Mon, 5 Jan 2009, Miosz Tylenda wrote:
>> I intentionally left supportsGetGeneratedKeys false because we don't
>> support returning generated keys by column indexes. Without knowing how
>> used that method is, I'm not sure if this is more or less helpful. I'm
>> open to input if people think we should change it to true.
>
> Kris, my picture is that I work with Apache OpenJPA - an object-
> relational mapper. OpenJPA checks whether generated keys are supported
> by calling DatabaseMetaData.supportsGetGeneratedKeys(). If true, the
> generated keys are retrieved from PreparedStatement by giving column
> names. If false, a second query is executed to get the value of
> sequence associated with serial column. So, in the OpenJPA context,
> supportsGetGeneratedKeys returning true would be more helpful, but I
> can also imagine a case where it would break things.
>
Please try this updated driver which supports generated keys for prepared
statements as well. I've also flipped supportsGetGeneratedKeys to true as
I believe that will be more helpful to more users.
http://ejurka.com/pgsql/jars/genkey/
Kris Jurka
From: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
---|---|
To: | Kris Jurka <books(at)ejurka(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2009-01-19 15:35:11 |
Message-ID: | 83a8ead10901190735j12686262la934f050897d45dc@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
> Please try this updated driver which supports generated keys for prepared
> statements as well. I've also flipped supportsGetGeneratedKeys to true as I
> believe that will be more helpful to more users.
>
> http://ejurka.com/pgsql/jars/genkey/
Kris,
Thanks for the update. I have done a few tests and it works.
supportsGetGeneratedKeys returns true and I was able to successfully
insert rows and get generated keys by using column names.
Best Regards,
Milosz
From: | Kris Jurka <books(at)ejurka(dot)com> |
---|---|
To: | Miłosz Tylenda <mtylenda(at)gmail(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Support of getting generated keys in driver version 8.4devel |
Date: | 2009-01-28 09:52:42 |
Message-ID: | 49802AEA.30701@ejurka.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-jdbc |
Miłosz Tylenda wrote:
>> Please try this updated driver which supports generated keys for prepared
>> statements as well. I've also flipped supportsGetGeneratedKeys to true as I
>> believe that will be more helpful to more users.
>>
>> http://ejurka.com/pgsql/jars/genkey/
>
> Thanks for the update. I have done a few tests and it works.
> supportsGetGeneratedKeys returns true and I was able to successfully
> insert rows and get generated keys by using column names.
>
I've committed this code to CVS.
Kris Jurka