Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 8A5789F9A08 for ; Mon, 17 Sep 2007 19:55:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 48137-08 for ; Mon, 17 Sep 2007 19:55:33 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id C95DF9F9A07 for ; Mon, 17 Sep 2007 19:55:31 -0300 (ADT) Received: from root by ciao.gmane.org with local (Exim 4.43) id 1IXPUc-0002tu-PJ for pgsql-jdbc@postgresql.org; Tue, 18 Sep 2007 00:55:02 +0200 Received: from cd4400510.cable.wanadoo.nl ([212.64.5.16]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 18 Sep 2007 00:55:02 +0200 Received: from sbailliez by cd4400510.cable.wanadoo.nl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 18 Sep 2007 00:55:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Stephane Bailliez Subject: Exception while doing ResultSetMetadata.getColumnName() after select setval() Date: Tue, 18 Sep 2007 00:30:57 +0200 Lines: 94 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: cd4400510.cable.wanadoo.nl User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/88 X-Sequence-Number: 17510 jdbc driver: postgresql-8.1-410.jdbc3.jar Sun jdk 1.6.0_01 windows xp postgresql 8.1.5 on windows xp and postgresql 8.1.9 on ubuntu Came across what looks like a bug in the driver when I wanted to realign sequences. Works fine when I inject everything from pgadmin, but I have a java code that insert every statement one by one and the 'verification' done by the code throws up an exception. sql is typically: create table mytable ( serial id ... ); insert table (id, ...) values (101, ...); .. -- this lines blows up with exception select setval ('mytable_id', max(id)) from mytable; It works fine if I wrap the select around another select ie something like this: select 1 from (select setval ('mytable_id', max(id)) from mytable) as workaround; Stacktrace is: org.postgresql.util.PSQLException: The column index is out of range: 0, number of columns: 1. at org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getField(AbstractJdbc2ResultSetMetaData.java:639) at org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getColumnLabel(AbstractJdbc2ResultSetMetaData.java:279) at org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getColumnName(AbstractJdbc2ResultSetMetaData.java:294) at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:175) at com.ibatis.common.jdbc.ScriptRunner.runScript(ScriptRunner.java:107) The code in iBatis does (see XXX note for line 175 reference) : [...] Statement statement = conn.createStatement(); println(command); boolean hasResults = false; if (stopOnError) { hasResults = statement.execute(command.toString()); } else { try { statement.execute(command.toString()); } catch (SQLException e) { e.fillInStackTrace(); printlnError("Error executing: " + command); printlnError(e); } } if (autoCommit && !conn.getAutoCommit()) { conn.commit(); } ResultSet rs = statement.getResultSet(); if (hasResults && rs != null) { ResultSetMetaData md = rs.getMetaData(); int cols = md.getColumnCount(); for (int i = 0; i < cols; i++) { String name = md.getColumnName(i); // XXX Exception here print(name + "\t"); } println(""); while (rs.next()) { for (int i = 0; i < cols; i++) { String value = rs.getString(i); print(value + "\t"); } println(""); } } command = null; try { statement.close(); } catch (Exception e) { // Ignore to workaround a bug in Jakarta DBCP } [...] cheers, -- stephane