列未在postgresql中更新
我尝试更新我的表,如下所示:列未在postgresql中更新,postgresql,Postgresql,我尝试更新我的表,如下所示: $query = "select * FROM sites s, companies c, tests t WHERE t.test_siteid = s.site_id AND c.company_id = s.site_companyid AND t.test_typeid = '20'
$query = "select *
FROM sites s, companies c, tests t
WHERE t.test_siteid = s.site_id
AND c.company_id = s.site_companyid
AND t.test_typeid = '20' AND s.site_id = '1337'";
$queryrow = $db->query($query);
$results = $queryrow->as_array();
foreach($results as $key=>$val){
$update = "update tests set test_typeid = ? , test_testtype = ? where test_siteid = ?";
$queryrow = $db->query($update,array('10','Meter Calibration Semi Annual',$val->site_id));
}
以上代码运行良好。但是在更新查询中,列test_typeid没有使用'10'更新。列test_typeid正在更新为空值。其他栏目的更新情况良好。我不知道为什么这个列test\u typeid没有更新?并且列test_typeid类型仅为整数。我正在使用postgreSql
我的表定义是:
我对代码所做的错误。请给我一些建议
提前谢谢 首先,学会使用正确的
JOIN
语法。切勿在FROM
子句中使用逗号;始终使用正确的显式JOIN
语法
您可以在一条语句中编写查询:
update tests t
set test_typeid = '10',
test_testtype = 'Meter Calibration Semi Annual'
from sites s join
companies c
on c.company_id = s.site_companyid
where t.test_siteid = s.site_id and
t.test_typeid = 20 and s.site_id = 1337;
我假设ID是数字,因此无需使用单引号进行比较。请向我们展示表格“测试”的定义@Meiko I附上了我表格的定义。请参考$queryrow=$db->query($update,array(10,'Meter Calibration Semi-year',$val->site_id))@美子是的,我试过了。它正在更新列的空值。您是否尝试将
test\u typeid
的类型更改为varchar
?您是否尝试在那里设置一些值,然后使用该脚本对其进行更新,以查看它是否会删除值?我已经尝试使用正确的联接进行查询。不管怎样,它不起作用。所以我只写了尽可能简单的查询。你的和我的一样。连接没有问题。我需要一个不更新列的解决方案。该列为整数,但未更新。我也删除了引号并尝试了。它还不能工作。