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 7F163D1B179 for ; Wed, 28 Jul 2004 22:47:17 -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 58513-07 for ; Thu, 29 Jul 2004 01:47:11 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id C6460D1B272 for ; Wed, 28 Jul 2004 22: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 i6T1l7qb041502 for ; Thu, 29 Jul 2004 01:47:07 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6T1OIkE038643 for pgsql-jdbc@postgresql.org; Thu, 29 Jul 2004 01:24:18 GMT From: "Mike Martin" X-Newsgroups: comp.databases.postgresql.interfaces.jdbc Subject: Re: Wrong column names in ResultSetMetaData Date: Wed, 28 Jul 2004 20:24:00 -0500 Organization: Vieo, Inc. Lines: 51 Message-ID: References: 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/314 X-Sequence-Number: 10698 I wrote: > 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". I think I see the problem. v2/QueryExecutorImpl.java:400 says: fields[i] = new Field(columnLabel, columnLabel, typeOid, typeLength, typeModifier, 0, 0); whereas v3/QueryExecutorImpl.java:1097 says: fields[i] = new Field(columnLabel, null, /* name not yet determined */ typeOid, typeLength, typeModifier, tableOid, positionInTable); and a separate query is later done in getColumnName() to try to return the unaliased *source* column name used in the query. I'm almost certain this is wrong from a JDBC standpoint. rsmd.getColumnName() is supposed to return the given name of the *result* column, which SQL has rules to define. rsmd.getColumnLabel() is "for use in printouts and displays" and will often equate to the column name unless the DBMS has some "prettier" column title for display purposes. For programmatic purposes the column name concept is pretty well defined by the docs on ResultSet. They're supposed to behave such that: String colname = rsmd.getColumnName(col); return rs.getXXX(colname); is equivalent to: return rs.getXXX(col); for every column that has a (non-duplicate) name. I have to think this is going to break more code than just ours. Mike