Postgres批量更新查询(从mysql转换)

时间:2013-07-27 22:10:54

标签: postgresql sql-update

我需要将查询转换为postgresql。我确切地说这个查询适用于mysql。

UPDATE cache_implementation n
INNER JOIN cache_compared compared ON n.compared_id = compared.nid
LEFT JOIN cache_implementation ncp ON (compared.parent_id = ncp.compared_id AND n.feature_id = ncp.feature_id)
INNER JOIN cache_feature feature ON n.feature_id = feature.nid
LEFT JOIN cache_implementation nfp ON (feature.parent_id = nfp.feature_id AND n.compared_id = nfp.compared_id)
SET n.parent_through_compared_id = ncp.nid, n.parent_through_feature_id = nfp.nid

当我尝试执行它时,附近有语法错误 第2行:INNER JOIN cache_compared比较ON n.com ...

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

尝试:

UPDATE cache_implementation
SET cache_implementation.parent_through_compared_id = ncp.nid, 
    cache_implementation.parent_through_feature_id = nfp.nid
FROM cache_implementation n
INNER JOIN cache_compared compared ON n.compared_id = compared.nid
LEFT JOIN cache_implementation ncp ON (compared.parent_id = ncp.compared_id AND n.feature_id = ncp.feature_id)
INNER JOIN cache_feature feature ON n.feature_id = feature.nid
LEFT JOIN cache_implementation nfp ON (feature.parent_id = nfp.feature_id AND n.compared_id = nfp.compared_id)
WHERE cache_implementation.compared_id = n.compared_id
  AND cache_implementation.feature_id  = n.feature_id;