Bug #32504 Column alias names not returned in query result set
Submitted: 19 Nov 2007 21:01 Modified: 13 Sep 2012 8:40
Reporter: Tony Pallas Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.5 OS:Linux (2.6.18-1.2798.fc6_HPTRAID)
Assigned to: CPU Architecture:Any
Tags: column alias, column naming, query result set

[19 Nov 2007 21:01] Tony Pallas
Description:
After upgrading to Connector/J 5.1.5 (from 3.1.12), we have noticed that when executing a stored procedure that uses a column alias in the SELECT clause (e.g. SELECT column_name AS my_custom_column_name) the alias column name is no longer returned in the result set.  Instead the actual column name is returned.  In prior releases, the alias name was returned as expected.

Once exception to this bug is when asking for the count to be returned as part of the result set.  The statement SELECT count(*) AS request_count FROM foo does indeed return the result with the proper alias column name 'request_count'

In our particular case, we are using Commons dbutils (1.1) and using a MapListHandler to deal with the result set.  Database is MySQL v5.0.27. Both client and server are running on Linux/FC6 2.6.18

How to repeat:
Create a stored procedure to execute a simple query and specify a column alias as part of the select statement:

SELECT  x, y AS custom_y FROM foo;

Suggested fix:
Restore behavior of previous releases to return a column alias in a query result set.
[20 Nov 2007 11:24] Tonci Grgin
Hi Tony and thanks for your report. I believe this is a duplicate of Bug#31499. Can you check your code with "useOldAliasMetadataBehavior=true" as a configuration parameter in your JDBC URL please. What does calling ResultSetMetaData.getColumnLabel()say?
[21 Dec 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[29 Oct 2008 2:00] Andrew MacDonald
I can comment.

I ran into this, because I assumed that getColumnName() would return the alias.  From what I've been reading is that in previous versions, it did.  getColumnLabel() returns what I was expecting.  I was a little confused though, because getColumnName() does return the alias of a COUNT(*); rather than, "COUNT(*)".

In any case, useOldAliasMetadataBehavior=true does make getColumnName() return what I, and I assume the submitter, was expecting.  I'm just going to use getColumnLabel() though (now that I realize it's there).