0

this thing is making me stupid for nothing since yesterday (googled a lot without finding any other developer with the same problem). I'm upgrading an application server written in java (jdk5), which uses postgresql 7, to jdk7 using postgresql 9.

the simple & absurd issue:

an INSERT and a SELECT in the same statement:

insert into table(a,b) values('a','b') ; select currval('table_pkey_id')

nothing special, seems simple and clear.. but with postgresql-9.3-1100.jdbc3.jar does not work more, throws the error in subject.

the sql statement works as usual using pgadmin, returning the id of the inserted line. but making the same query using javam with pg9/java7, it throws the error like if I use executeQuery on a simple insert statement.

stmt=cnn.createStatement(rst.TYPE_SCROLL_INSENSITIVE,rst.CONCUR_READ_ONLY);
stmt.executeQuery(sql);

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

why god?! I want and need to fix this issue WITHOUT breaking in 2 sql statements the one above. seems a really stupid bug in executeQuery implementation.

please feedback. thanks.

max

Chris Travers
  • 25,424
  • 6
  • 65
  • 182

1 Answers1

0

I think you would do better to change to:

insert into table(a,b) values('a','b') RETURNING id;

RETURNING is now supported in all supported versions of PostgreSQL.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
  • Or better yet, use the JDBC `getGeneratedKeys` feature. – Mark Rotteveel Dec 07 '13 at 09:19
  • I have to try 'returning id' and getGeneratedKeys (this one sounds more non standard.. I will report results if they are interesting). in any case that sounds like a semi-serious and silly jdbc bug. thanks. max – Massimiliano Carli Dec 09 '13 at 06:47