Bug #93994 Parameter marker aliases in inner SELECTs are not propagated to outer SELECTs
Submitted: 21 Jan 15:08 Modified: 7 Feb 14:25
Reporter: GC GC Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.6.17 OS:Any
Assigned to: CPU Architecture:Any

[21 Jan 15:08] GC GC
Description:
A call to SQLPrepare with:
const char *sql = "SELECT X, Y FROM (SELECT 1 X, ? AS Y) Q";
fails with "[MySQL][ODBC 5.3(a) Driver][mysqld-5.6.17] Unknown column 'Y' in 'field list'"

Workaround (replace single parameter with 2 inside a COALESCE):
const char *sql = "SELECT X, Y FROM (SELECT 1 X, COALESCE(?, ?) Y) Q";

Also works: sql without the outer select

Also fails (with "Unknown column 'Q.Y' in 'field list'"): 
const char *sql = "SELECT Q.X, Q.Y FROM (SELECT 1 X, ? Y) Q";

So the bug seems to be that parameter marker aliases in inner SELECTs are not propagated to the outer SELECTs.

How to repeat:
Execute the aforementioned SQL statement using a MySQL ODBC driver.
[24 Jan 19:50] GC GC
Discovered that the bug does not occur against a MySQL server version 5.6.40.
[7 Feb 14:25] Miguel Solorzano
Thank you for the feedback. Closed according your last comment.