Bug #41235 Using * and a function in a SELECT can cause a SQL syntax error (ERROR 1064)
Submitted: 4 Dec 2008 16:41 Modified: 4 Dec 2008 17:49
Reporter: marc bourbonnais Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.1.29, 4.1, 5.0, 5.1, 6.0 bzr OS:Any (Mac OS X, Linux)
Assigned to: CPU Architecture:Any

[4 Dec 2008 16:41] marc bourbonnais
Description:
When doing a query that contains both * and a function (UTC_TIMESTAMP(), IF(), etc...), the order in the select causes different result. In some cases, it works, in the other, it will cause ERROR 1064.

Works:
1. SELECT *,IF(...) FROM ... 
2. SELECT IF(...), t.* FROM ... as t
3. SELECT IF(...), t.* FROM t

Causes Error 1064:
1. SELECT IF(...),* FROM ...

How to repeat:
Here is the example, I used a "in-bedded" table, but any table will cause the problem:

mysql> select UTC_TIMESTAMP(),* from (select 1 from dual) as t;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* from (select 1 from dual) as t' at line 1

mysql> select UTC_TIMESTAMP(),t.* from (select 1 from dual) as t;
+---------------------+---+
| UTC_TIMESTAMP()     | 1 |
+---------------------+---+
| 2008-12-04 16:26:15 | 1 | 
+---------------------+---+

mysql> select *,UTC_TIMESTAMP() from (select 1 from dual) as t;
+---+---------------------+
| 1 | UTC_TIMESTAMP()     |
+---+---------------------+
| 1 | 2008-12-04 16:26:28 | 
+---+---------------------+
[4 Dec 2008 17:49] Sveta Smirnova
Thank you for the report.

Verified as described.