I execute the following query in postgres:
UPDATE products SET dealer_id =
CASE
WHEN order_id = 7 THEN '1'
WHEN order_id = 6 THEN '2'
ELSE dealer_id
END
RETURNING id
I expect to get ids of the updated rows like [3,4,5] but it returns all rows ids
what's wrong with my query?
You have no
where
clause, so you are updating all rows.I think you intend:
You may be interested in this explanation of why all rows are affected when you don't include a
WHERE
clause.