我得到错误
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"
我的代码是
$sql = ...
."having sum(clicks)/sum(impressions) < :ctr ";
$ids = Yii::$app->db->createCommand($sql)
->bindValue(':ctr', (float)getConfigValue('ctr'))
->queryColumn();
我尝试将第三个参数设置为'PDO::PARAM_STR
,但它仍然给出相同的错误。我也试图删除(float)
铸型,但同样的错误。甚至没有可用的十进制类型:http://php.net/manual/en/pdo.constants.php
这在MySQL中工作。我正在迁移到Postgres。SQL直接在psql
中工作。
参考:http://www.yiiframework.com/doc - 2.0/- yii - db - command.html # bindValue()细节
在Postgres中,将两个整数除在一起是整数除法,因此您将整数与浮点数进行比较。
select 2/3; -- returns 0
select 2/3.0; -- returns 0,6666…7
试试having sum(clicks)/cast(sum(impressions) as float4) < 0.0001