使用内部连接更新 Postgresql
Posted
技术标签:
【中文标题】使用内部连接更新 Postgresql【英文标题】:Update with inner join Postgresql 【发布时间】:2017-05-22 17:35:08 【问题描述】:因为执行此更新不适用于 where 子句?更新对我来说都是如此。
UPDATE ventas SET eav_id = 7
FROM ventas AS A
inner join ventasDetalle AS e on A.act_id = e.act_id and e.exp_id = A.exp_id
where a.eav_id = 1
【问题讨论】:
【参考方案1】:update ventas a
set eav_id = 7
from ventasDetalle e
where a.eav_id = 1 and (a.act_id, a.exp_id) = (e.act_id, e.exp_id)
【讨论】:
【参考方案2】:Postgresql UPDATE 语法是:
[ 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 ventas AS A
SET eav_id = 7
FROM ventasDetalle AS e
WHERE (A.act_id = e.act_id and e.exp_id = A.exp_id)
【讨论】:
以上是关于使用内部连接更新 Postgresql的主要内容,如果未能解决你的问题,请参考以下文章