【发布时间】:2013-01-30 15:40:01
【问题描述】:
我是 postresql 的新手,我很惭愧地认识到我不确定如何正确执行更新。
每次我尝试 pg_query($update);它给了我这个:查询失败:错误:无法在只读事务中执行更新。
在此更新之前,我执行了一个选择查询。
select 语句从数据库中检索 50000 行。更具体地说,我正在尝试对 1000 行执行 when /case 更新。查询格式正确,我已经测试过了。
$sqlstr = "update abcd set country = CASE" ;
$temp = "";
while($myrow = pg_fetch_assoc($result)) {
if ($cnt < 1000) {
$country = exec('geoiplookup '.$myrow['ip']);
$temp .= " WHEN id = ".$myrow['id']." then '".$country."'";
$cnt++;
}
else {
$sqlstr = $sqlstr.$temp." END ; ";
pg_query($sqlstr);
$temp = "";
}
}
【问题讨论】:
-
$sqlstr = "update abcd set country = CASE" ; $临时=“”; while($myrow = pg_fetch_assoc($result)) { if ($cnt
-
1:更新您的问题,而不是添加评论,因为格式化是一种痛苦等。 2:您将交易设置为只读。可能是您正在使用的工具等。
标签: php postgresql sql-update updates case-when