Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0BE05632D3C for ; Tue, 29 Dec 2009 08:20:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 05566-09 for ; Tue, 29 Dec 2009 12:20:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail.postgresql.org (Postfix) with ESMTP id 526CB632BFA for ; Tue, 29 Dec 2009 08:20:07 -0400 (AST) Received: by leary.csoft.net (Postfix, from userid 1112) id 1F677A35C; Tue, 29 Dec 2009 07:20:05 -0500 (EST) Date: Tue, 29 Dec 2009 07:20:04 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Oliver Jowett cc: Gianvito Pio , pgsql-jdbc@postgresql.org Subject: Re: Get a table name In-Reply-To: <4B3809D7.9090407@opencloud.com> Message-ID: References: <4B3737DA.4070408@gmail.com> <4B3809D7.9090407@opencloud.com> User-Agent: Alpine 2.00 (BSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.572 tagged_above=-10 required=5 tests=AWL=0.027, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/107 X-Sequence-Number: 20188 On Mon, 28 Dec 2009, Oliver Jowett wrote: > We concluded a while back that getTableName() is meant to return the > aliased table name in the query, not the underlying table name. It's not > easy for the driver to find the aliased name, so it always returns an > empty string, as you found. > Just recently I was reading the Mysql JDBC driver's documentation [1] and came across the "useColumnNamesInFindColumn" config option that comes with this description: Prior to JDBC-4.0, the JDBC specification had a bug related to what could be given as a "column name" to ResultSet methods like findColumn(), or getters that took a String property. JDBC-4.0 clarified "column name" to mean the label, as given in an "AS" clause and returned by ResultSetMetaData.getColumnLabel(), and if no AS clause, the column name. Setting this property to "true" will give behavior that is congruent to JDBC-3.0 and earlier versions of the JDBC specification, but which because of the specification bug could give unexpected results. This property is preferred over "useOldAliasMetadataBehavior" unless you need the specific behavior that it provides with respect to ResultSetMetadata. This claims that we've got things backwards now despite our extensive previous discussion because the spec was misleading. I gave the JDBC 4 spec another read and didn't find anything particularly revealing, but taking a look at the Javadoc for getColumnLabel [2] does clear things up: Gets the designated column's suggested title for use in printouts and displays. The suggested title is usually specified by the SQL AS clause. If a SQL AS is not specified, the value returned from getColumnLabel will be the same as the value returned by the getColumnName method. For reference the previous discussion started at [3] and continued to [4]. So it looks like we should fix this up and ensure there's a way of getting to old mode as well. Kris Jurka [1] http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html [2] http://java.sun.com/javase/6/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel(int) [3] http://archives.postgresql.org/pgsql-jdbc/2004-07/threads.php#00314 [4] http://archives.postgresql.org/pgsql-jdbc/2004-08/threads.php#00008