X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A5123D1B171 for ; Wed, 28 Jul 2004 20:47:18 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22318-04 for ; Wed, 28 Jul 2004 23:47:11 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id ADAD2D1B16B for ; Wed, 28 Jul 2004 20:47:07 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i6SNl6qb026802 for ; Wed, 28 Jul 2004 23:47:06 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6SNhchQ026352 for pgsql-jdbc@postgresql.org; Wed, 28 Jul 2004 23:43:38 GMT From: "Mike Martin" X-Newsgroups: comp.databases.postgresql.interfaces.jdbc Subject: Wrong column names in ResultSetMetaData Date: Wed, 28 Jul 2004 18:43:44 -0500 Organization: Vieo, Inc. Lines: 74 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 To: pgsql-jdbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=PRIORITY_NO_NAME X-Spam-Level: X-Archive-Number: 200407/315 X-Sequence-Number: 10699 With the new V3 driver the column names in ResultSetMetaData don't reflect the aliases used in the SQL. I.e. if I do: SELECT name as name_alias FROM ... the metadata says I have a result column called "name" instead of "name_alias". Client: PostgreSQL 7.5devel JDBC2 with SSL (build 304) Server: PostgreSQL 7.4.2 on i386-redhat-linux-gnu, compiled by GCC 2.96 The code below works with the 7.4 driver but fails with 7.5. Is this more likely to be in the driver or in the server-side V3 code? Mike AliasTest.java ------------------- import java.sql.*; import java.util.*; public class AliasTest { public static void main(String args[]) throws Exception { if (args.length != 3) throw new IllegalArgumentException("usage: java AliasTest "); Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql:" + args[0], args[1], args[2]); Statement stmt = conn.createStatement(); try { stmt.execute("DROP TABLE alias_test"); } catch (SQLException e) {} stmt.execute("CREATE TABLE alias_test ( name varchar(64) not null primary key )"); stmt.executeUpdate("INSERT INTO alias_test ( name ) VALUES ( 'abc' )"); stmt.close(); PreparedStatement ps = conn.prepareStatement("SELECT name as name_alias FROM alias_test"); ResultSet rs = ps.executeQuery(); if (!rs.next()) throw new Exception("No row?"); List expectedColumnNames = Arrays.asList(new String[] { "name_alias" }); List actualColumnNames = new ArrayList(); ResultSetMetaData rsmd = rs.getMetaData(); int colCount = rsmd.getColumnCount(); for (int colNum = 1; colNum <= colCount; ++colNum) actualColumnNames.add(rsmd.getColumnName(colNum)); if (!expectedColumnNames.equals(actualColumnNames)) throw new Exception("Wrong column names in result set metadata, expected " + expectedColumnNames + ", got " + actualColumnNames); rs.close(); ps.close(); conn.close(); } }