基本上,我想这样做:
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... ^
UPDATE syntax是:
原文链接:https://www.f2er.com/postgresql/194050.html[ WITH [ RECURSIVE ] with_query [,...] ] UPDATE [ ONLY ] table [ [ AS ] alias ] SET { column = { expression | DEFAULT } | ( column [,...] ) = ( { expression | DEFAULT } [,...] ) } [,...] [ FROM from_list ] [ WHERE condition | WHERE CURRENT OF cursor_name ] [ RETURNING * | 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