0

我需要将查询转换为 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...

感谢您的帮助。

4

1 回答 1

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;
于 2013-07-27T23:52:28.360 回答