sqlcoldfusionqoq

Using a wildcard operator in a query of query


I have the following code:

<cfquery name="somequery1" datasource="somedsn">
    SELECT somecolumn1, somecolumn2, somecolumn3 
    FROM sometable 
    WHERE someid = <cfqueryparam cfsqltype="cf_sql_integer" value="1">
</cfquery>

<cfquery name="somequery2" dbtype="query">
    SELECT *
    FROM somequery1
</cfquery>

My code manager says I need to change the Query of Query to:

<cfquery name="somequery2" dbtype="query">
    SELECT somecolumn1, somecolumn2, somecolumn3 
    FROM somequery1
</cfquery>

Can someone explain why I would need to redefine the column references in the Query of Query? Surely, the wildcard operator takes care of this.

Is there any technical or performance gain to redefining the column references in the SELECT clause of a Coldfusion Query of Queries? This assumes that the column references have already been explicitly set in the database query that is supplied to the Query of Queries.

I believe the use of the wildcard operator makes the code cleaner and easier to update, because any changes to the column references only need to be done once.


Solution

  • As you've discussed with Rahul: your "code manager" is offering good advice if this was a DB-based query, but I think it's a bit egregious in the context of a CFML query-on-query.

    I suspect they have heard the guidance in the context of DB queries, and have not really thought it through sufficiently when giving guidance on in-memory query operations.

    In short: your code is more optimal as it stands than the change's they're advising.