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 236EDD1B1CD for ; Mon, 2 Aug 2004 20:18:14 -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 68702-08 for ; Mon, 2 Aug 2004 23:18:15 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id ECAFAD1B1B4 for ; Mon, 2 Aug 2004 20:18:12 -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 i72NICqd077833 for ; Mon, 2 Aug 2004 23:18:12 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i72N5ZKZ076569 for pgsql-jdbc@postgresql.org; Mon, 2 Aug 2004 23:05:35 GMT From: "Mike Martin" X-Newsgroups: comp.databases.postgresql.interfaces.jdbc Subject: Re: Wrong column names in ResultSetMetaData Date: Mon, 2 Aug 2004 18:06:35 -0500 Organization: Vieo, Inc. Lines: 57 Message-ID: References: <41086EF8.7010101@opencloud.com> 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: 200408/15 X-Sequence-Number: 10737 Kris wrote: > > PostgreSQL 7.5 price orig_price price "" > > I think you have the name and column for 2 backwards. It should return "" > for the column name because it is a derived column, so there is no > underlying table column to return. Sorry, you're right. I inadvertently reversed them in the process of table-ization. > This shows the results are different, but it doesn't indicate why. Is it > simply because the other dbs can't implement getColumnName as we have? > I certainly wouldn't expect this to be a common feature. > > Further it doesn't show that users can't write portable code using the > ResultSetMetaData calls. It shows all drivers returning the same value > for getColumnLabel that you would expect. Earlier you had speculated that > other drivers would return something different for this, but you haven't > shown that. Yes it may break existing code, but it doesn't show that they > weren't simply using the wrong call. No, I speculated that a driver *could*, if it had a special pretty print label available from the DBMS, return it from getColumnLabel(). Most DBMS's don't. Oracle does in SQL*Plus; for example: column c1 heading "# OF ROWS" format 99,999,999; column c2 heading "#_rows*row_len" format 9,999,999,999; column c3 heading "PCT USED" format 999; select num_rows c1, num_rows*avg_row_len c2, ((num_rows*avg_row_len)/(blocks*&blksz))*100 c3 from perfstat.stats$tab_stats a ... Does their driver support that? I don't know. But it is an example of exactly what the docs for getColumnLabel() describe: the "suggested title for use in printouts and displays". In the absence of such support, doesn't it make sense that driver writers would have simply defaulted label to column name? I don't see anything ambiguous in "suggested title for use in printouts and displays", nor anything that would even remotely tie it to SQL alias. But I do see, and have given you, text that explicitly ties column names to SQL aliases. Plus evidence that many other well-known drivers work on that basis. And you can't just ask everyone to switch their getColumnName() to getColumnLabel(). It doesn't even work because of findColumn() and rs.getXXX(String). Those methods are *required* to resolve a duplicate name to the first matching column (ResultSet Javadoc). With your code, my rs.getFloat("PRICE") *must* resolve to column 1, and that's simply the wrong answer. Mike