Unix Technical Forum

currval bug??

This is a discussion on currval bug?? within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> Hi all, i have recently upgraded my development environment: FROM postgresql 7.4 TO postgresql 8.0beta5 FROM jdk1.4 TO jdk1.5 ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:54 PM
Gabriele Carteni
 
Posts: n/a
Default currval bug??

Hi all,
i have recently upgraded my development environment:
FROM postgresql 7.4 TO postgresql 8.0beta5
FROM jdk1.4 TO jdk1.5
FROM pg74.215.jdbc3.jar TO pg80b1.308.jdbc3.jar

now, i have a FRUSTRATING bug:

With this query (which works fine with previous pg74jdbc):

*insert into tablename (fieldname) values ('testvalue');select
currval('tablename_id_seq');*

this exeception was throwed:

*org.postgresql.util.PSQLException: No results were returned by the query.*

Obviously the query has to return a result.

Any idea?
thanks!!
gaboc

--
__________________________________________________ ___________

"Microsoft isn't the answer. Microsoft is the question, and my answer is no!"


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 10:54 PM
Kris Jurka
 
Posts: n/a
Default Re: currval bug??



On Tue, 21 Dec 2004, Gabriele Carteni wrote:

> Hi all,
> i have recently upgraded my development environment:
> FROM postgresql 7.4 TO postgresql 8.0beta5
> FROM jdk1.4 TO jdk1.5
> FROM pg74.215.jdbc3.jar TO pg80b1.308.jdbc3.jar
>
> now, i have a FRUSTRATING bug:
>
> With this query (which works fine with previous pg74jdbc):
>
> *insert into tablename (fieldname) values ('testvalue');select
> currval('tablename_id_seq');*
>
> *org.postgresql.util.PSQLException: No results were returned by the query.*
>
> Obviously the query has to return a result.


The 7.4 driver sends the whole query string together to the backend and
gets a result. The 8.0 driver splits the query into two and sends them
individually. This is required to use the V3 extended query protocol.
When it gets the result from the first part it is expecting a result and
isn't getting one. I'm not sure if this should be an error or not, in
general mashing queries together isn't a great idea. Perhaps you should
be using Statement.execute() and then iterating through any/all results
returned?

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:54 PM
Gabriele Carteni
 
Posts: n/a
Default Re: currval bug??

Hi Kris and thank you for your fast answer..

my problem is to retrieve the last autogenerated key after an insert
statement.
i always used this method (mashing queries together where the last is a
currval query).
What i should use to have the same result in pgsql8?

i apologize that java.sql.Statement.getGeneratedKeys() isn't still
implemented.

thanks!
gaboc

Kris Jurka wrote:

>On Tue, 21 Dec 2004, Gabriele Carteni wrote:
>
>
>
>>Hi all,
>>i have recently upgraded my development environment:
>>FROM postgresql 7.4 TO postgresql 8.0beta5
>>FROM jdk1.4 TO jdk1.5
>>FROM pg74.215.jdbc3.jar TO pg80b1.308.jdbc3.jar
>>
>>now, i have a FRUSTRATING bug:
>>
>>With this query (which works fine with previous pg74jdbc):
>>
>>*insert into tablename (fieldname) values ('testvalue');select
>>currval('tablename_id_seq');*
>>
>>*org.postgresql.util.PSQLException: No results were returned by the query.*
>>
>>Obviously the query has to return a result.
>>
>>

>
>The 7.4 driver sends the whole query string together to the backend and
>gets a result. The 8.0 driver splits the query into two and sends them
>individually. This is required to use the V3 extended query protocol.
>When it gets the result from the first part it is expecting a result and
>isn't getting one. I'm not sure if this should be an error or not, in
>general mashing queries together isn't a great idea. Perhaps you should
>be using Statement.execute() and then iterating through any/all results
>returned?
>
>Kris Jurka
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>
>
>



--
__________________________________________________ ___________
Ing. Gabriele Carteni
Center for Advanced Computational Technologies / ISUFI
University of Lecce, Italy

office: +39.0832.298.122
ICQ#: 128087012

gpg --recv-keys --keyserver pgp.mit.edu 0x54E5C362

"Microsoft isn't the answer. Microsoft is the question, and my answer is no!"


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 10:54 PM
Kris Jurka
 
Posts: n/a
Default Re: currval bug??



On Tue, 21 Dec 2004, Gabriele Carteni wrote:

> my problem is to retrieve the last autogenerated key after an insert
> statement. i always used this method (mashing queries together where the
> last is a currval query). What i should use to have the same result in
> pgsql8?
>


Well, as I mentioned in my previous email, I'm not sure if this is an
error in the JDBC driver. We could conceivably return the first result
found from a combined query like you've shown. I'm not sure what the code
implications are, but it seems like a reasonable thing to do from an
interface perspective.

To get this working with the current code you will probably have to split
it up into individual queries. In my previous email I also mentioned that
using Statement.execute() instead of Statement.executeQuery() might work,
but I've not tested it.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com