gpt4 book ai didi

php - 如何在 Yii for Postgres 中将 float 绑定(bind)到 SQL 命令?

转载 作者:行者123 更新时间:2023-11-29 12:19:47 25 4
gpt4 key购买 nike

我得到了错误

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();

我尝试将第 3 个参数设置为 \PDO::PARAM_STR,但它仍然给出相同的错误。我也尝试删除 (float) Actor ,但同样的错误。甚至没有可用的小数类型:http://php.net/manual/en/pdo.constants.php

这在 MySQL 中有效。我正在迁移到 Postgres。 SQL 直接在 psql 中运行。

引用:http://www.yiiframework.com/doc-2.0/yii-db-command.html#bindValue()-detail

最佳答案

在 Postgres 中,将两个整数相除就是整数除法,因此您将整数与 float 进行比较。

select 2/3; -- returns 0
select 2/3.0; -- returns 0,6666…7

尝试 having sum(clicks)/cast(sum(impressions) as float4) < 0.0001

关于php - 如何在 Yii for Postgres 中将 float 绑定(bind)到 SQL 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32730553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com