Bug #42453 Column name overriding
Submitted: 29 Jan 2009 14:03 Modified: 29 Jan 2009 14:35
Reporter: Alex P Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.0.51a-community OS:Any
Assigned to: CPU Architecture:Any
Tags: column name, overriding

[29 Jan 2009 14:03] Alex P
Description:
Looks like column name is overridden when two column names are separated by new line and not by comma. For example if i execute this query:

select
   `ad_id`,
   `ad_ca_id`
from 
   `ads`
limit 1

everything is ok. two columns in results are returned:

+-------+--------+
| ad_id |ad_ca_id|
+-------+--------+
|3385482|       0|
+-------+--------+

But if i execute this query (with missing comma between two columns):

select
   `ad_id`
   `ad_ca_id`
from 
   `ads`
limit 1

mysql server doesn't produce error and outputs this:

+--------+
|ad_ca_id|
+--------+
| 3388712|
+--------+

so not only a column is missing, but the result it self is wrong (should be 0)

How to repeat:
Execute query with structure like this one:

select
   `ad_id`
   `ad_ca_id`
from 
   `ads`
limit 1
[29 Jan 2009 14:27] Valeriy Kravchuk
This is not a bug. Without comma second name is treated as column alias. Please, read http://dev.mysql.com/doc/refman/5.0/en/select.html:

"However, because the AS is optional, a subtle problem can occur if you forget the comma between two select_expr expressions: MySQL interprets the second as an alias name. For example, in the following statement, columnb is treated as an alias name:

SELECT columna columnb FROM mytable;

For this reason, it is good practice to be in the habit of using AS explicitly when specifying column aliases."
[29 Jan 2009 14:35] Alex P
ahr.. yes X) didn't intended to use it as alias so run into that problem. Thank you for explain.