基本上,我想这样做:update vehicles_vehicle v join shipments_shipment s on v.shipment_id=s.id set v.price=s.price_per_vehicle;我很确定这可以在MySQL(我的背景)中使用,但似乎在postgres中不起作用。我得到的错误是:ERROR: syntax error at or near "join"LINE 1: update vehicles_vehicle v join shipments_shipment s on v.shi... ^当然,有一种简单的方法可以执行此操作,但是我找不到正确的语法。那么,我将如何在PostgreSQL中编写此代码?
3 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
该UPDATE语法是:
[WITH [RECURSIVE] with_query [,...]]
更新[仅]表[[AS]别名]
SET {列= {表达式| 默认} |
(column [,...])=({表达式| DEFAULT} [,...])} [,...]
[FROM from_list]
[状况| cursor_name的当前位置]
[返回* | output_expression [[AS] output_name] [,...]]
在您的情况下,我认为您需要这样做:
UPDATE vehicles_vehicle AS v
SET price = s.price_per_vehicle
FROM shipments_shipment AS s
WHERE v.shipment_id = s.id
- 3 回答
- 0 关注
- 659 浏览
添加回答
举报
0/150
提交
取消