use sql function with querybuilder

Hi

How would I use a built in SQL function with Querybuilder? I am trying to use IFNULL within a select statement

My code is:




$q = new Query;

$q->select('score');


// I tried $q->select('IFNULL(score,0)');



But that got parsed as SELECT IFNULL(score, 0)

Thanks

Wrap it with http://www.yiiframework.com/doc-2.0/yii-db-expression.html

Hi alex

I tried:




$expression = new Expression('IFNULL(score, 0)');

                    $query->select($expression);



But it still got executed as




SELECT IFNULL(score, `0)` 



What did I do wrong?

try it:




$q->select(['IFNULL(score,0)']);

No that didn’t work either :frowning:

What is error message ?

This is working with postgres driver.

You may use selectOptions property too.

My mistake, it does work. I was tired last night.

Jonathon