Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update with inner join Postgresql

Because doing this update does not work for the where clause? The update does it for me all.

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
like image 818
Max Avatar asked Sep 15 '25 00:09

Max


2 Answers

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)
like image 64
Clodoaldo Neto Avatar answered Sep 17 '25 18:09

Clodoaldo Neto


The Postgresql UPDATE syntax is:

[ 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 ] [, ...] ]

So I think you want:

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)
like image 26
Billy Ferguson Avatar answered Sep 17 '25 18:09

Billy Ferguson