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 626A1D1B343 for ; Thu, 29 Jul 2004 14:47:28 -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 80848-01 for ; Thu, 29 Jul 2004 17:47:21 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 1E627D1B2D9 for ; Thu, 29 Jul 2004 14:47:19 -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 i6THlJqb087212 for ; Thu, 29 Jul 2004 17:47:19 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i6THjn19087014 for pgsql-jdbc@postgresql.org; Thu, 29 Jul 2004 17:45:49 GMT From: "Mike Martin" X-Newsgroups: comp.databases.postgresql.interfaces.jdbc Subject: Re: Wrong column names in ResultSetMetaData Date: Thu, 29 Jul 2004 12:45:32 -0500 Organization: Vieo, Inc. Lines: 71 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/324 X-Sequence-Number: 10708 "Kris Jurka" wrote: > > For programmatic purposes the column name concept is pretty > > well defined by the docs on ResultSet. > > I am not sure I see where it states that. Your logic makes some sense, > but I don't see anywhere it says the above explicity. The problem is how > to return both pieces of information (the alias and the underlying column > name) within the JDBC API. Certainly the alias makes more sense as the > label when you have to pick between the two of them. It depends on how explicit you need it to be. :) Unfortunately the JDBC spec itself lacks much of anything that explicit. The Javadoc for ResultSet says: "The column name option is designed to be used when column names are used in the SQL query that generated the result set. For columns that are NOT explicitly named in the query, it is best to use column numbers." I read "named" to mean named according to the usual SQL rules. Combine that with the other references to the semantics of column name (findColumn(), getXXX(colName)) and it seems like the reasonable reading. My other support is circumstantial: 1. An SQL query produces a result set which is itself a table, that table has columns, those columns have names, and those names are defined according to SQL rules. The column being named is that of the result table, not that of the underlying source(s) that contributed to it. I can't imagine getColumnName() referring to any other concept. 2. Every other JDBC driver I'm familiar with behaves that way (with the exception, I hear, of MimerSQL, which confuses getColumnLabel() with SQL alias the way our new code does). I'm not clear why a JDBC client would want or need to know the "underlying" column name, if there even is one. I can see why the driver might need to know that internally for purposes of updateability but that's something different. > Would you expect the results of getTableName() to return the underlying > table or the table's alias in the query? To be consistent with your > argument you'd have to claim the alias name which is useless here. The alias. By SQL naming rules every column may also have a table name component that can be used to disambiguate it from other columns of the same name. If a query represents a single table expression, and that expression has been given an alias name (aka "range variable"), then every column takes that alias as its table name. Likewise with getCatalogName(int) except I believe a column loses any catalog affiliation as soon as it's aliased in any way. > Further code doesn't make a whole lot of sense doing: > > rs.getString(rsmd.getColumnName(1)); > > Why wouldn't it just do: > > rs.getString(1); In real life you would. I was just illustrating the expected semantics. Mike