IMO, your first example shows the bug OR such a behavior isn’t documented properly - it is said CDbExpression is mainly used in CActiveRecord as attribute values, but your example works ONLY for setting attribute value (at least what I’ve got from my tests) properly.
In your example expression is partially escaped, and parameter is lost
Invalid parameter number: noparameters were bound.
The SQL statement executed was:
SELECT to_char(MAX(when_processed), `:df)`FROM `service`.`import_gld360_filenames`
When using with CDbCriteria, parameter is lost, but :df isn’t escaped. Example:
$criteria = new CDbCriteria(array(
'select'=>new CDbExpression('to_char(MAX(when_processed), :df)', array(':df'=>'YYYY-MM-DD')),
));
$user = Users::model()->find($criteria);
Invalid parameter number: noparameters were bound.
The SQL statement executed was:
SELECT to_char(MAX(when_processed), :df) FROM `users` `t` LIMIT 1.
Using your expression to set attribute value works properly:
INSERT INTO `users` (`name`) VALUES (to_char(MAX(when_processed), :df)). Bound with :df='YYYY-MM-DD'