After upgrading from 5.3.10.120 to 5.4.3.2 I’ve found several query of queries throwing errors.
Are these bugs?
Test case 1
<cfset queryOne = queryNew("column_one,column_two", "decimal,decimal", [[10.22, 100.33], [20.44, 200.55]]) />
<cfquery name="queryTwo" dbtype="query">
SELECT *, ROUND(column_one + column_two) AS column_three
FROM queryOne
</cfquery>
Throws the error:
duplicate column name in derived table
Workaround, remove the ROUND() function…
SELECT *, column_one + column_two AS column_three
Alternatively, listing the column names in the SELECT statement…
SELECT column_one, column_two, ROUND(column_one + column_two) AS column_three
…stops the errors but results in all the returned values being rounded.
Test case 2:
<cfset queryOne = queryNew("column_one,column_two", "decimal,decimal", [[10.22, 100.33], [20.44, 200.55]]) />
<cfquery name="queryTwo" dbtype="query">
SELECT column_one, column_two, column_one + column_two AS column_three
FROM queryOne
WHERE column_three > 200
</cfquery>
Trying to use the new column directly in the WHERE clause results in an empty recordset.
Workaround, repeat the calculation in the WHERE clause:
WHERE column_one + column_two > 200