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 51CFDD1B1B4 for ; Mon, 2 Aug 2004 20:58:05 -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 81456-04 for ; Mon, 2 Aug 2004 23:58:04 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 94986D1B182 for ; Mon, 2 Aug 2004 20:57:58 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1BrmgQ-0001DG-00; Tue, 03 Aug 2004 11:57:34 +1200 Message-ID: <410ED4E6.8020806@opencloud.com> Date: Tue, 03 Aug 2004 11:57:26 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kris Jurka Cc: Mike Martin , pgsql-jdbc@postgresql.org Subject: Re: Wrong column names in ResultSetMetaData References: <41086EF8.7010101@opencloud.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200408/17 X-Sequence-Number: 10739 Kris Jurka wrote: > 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. I'm leaning towards Mike's argument here. It seems reasonable that the column name returned is the same as what you'd use to look up a column by name via ResultSet, and the only sensible thing to do in ResultSet lookups is to use the column aliases. The argument for exposing the real column name as a way to allow portable updating of the underlying table seems weak given that other drivers don't support the same behaviour. The more portable behaviour seems to be to always use getColumnName() and forbid the use of AS in queries that you want to be updatable. getColumnLabel() isn't the right place for the underlying column name, though. JDBC doesn't actually seem to have a mapping for this concept at all. I'd suggest adding a PG-specific interface if we want to expose this. How about: RSMD.getColumnName() returns the column alias RSMD.getColumnLabel() returns the column alias, or maybe something like the column's comment (can you COMMENT ON columns?) later. PGResultSetMetadata.getSourceColumnName() returns the underlying table column name. The driver's updateable resultset code can use this when constructing update SQL. On a related note, if I execute this query: SELECT * FROM footable f should RSMD.getTableName() return "footable" or "f"? By analogy to RSMD.getColumnName() it should return "f", but it seems more useful to return "footable". -O