I get the error
Database Exception – yii\db\Exception
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "0.0001"
The SQL being executed was: select ad_id, sum(clicks) sc, sum(impressions) si, from ad_table group by keyword_id
having sum(clicks)/sum(impressions) < 0.0001
Error Info: Array
(
[0] => 22P02
[1] => 7
[2] => ERROR: invalid input syntax for integer: "0.0001"
)
↵
Caused by: PDOException
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "0.0001"
My code is
$sql = ...
."having sum(clicks)/sum(impressions) < :ctr ";
$ids = Yii::$app->db->createCommand($sql)
->bindValue(':ctr', (float)getConfigValue('ctr'))
->queryColumn();
I tried setting the 3rd parameter to \PDO::PARAM_STR, but it still gave the same error. I also tried removing the (float) cast, but same error. There is not even a decimal type available: http://php.net/manual/en/pdo.constants.php
This worked in MySQL. I'm migrating to Postgres. The SQL works directly in psql.
Reference: http://www.yiiframework.com/doc-2.0/yii-db-command.html#bindValue()-detail
yii\db\Queryat least?->having(['<', 'c', 20000]), so even though I usedQuery, I still had to change the code to->having(['<', 'count(*)', 20000]).