UPDATE
Modifies existing rows. Always include WHERE to avoid updating all rows. Supports RETURNING to fetch updated values.
Syntax
postgresql
UPDATE table SET col = val WHERE condition RETURNING cols;Example
postgresql
UPDATE users
SET last_login = NOW(),
login_count = login_count + 1
WHERE id = $1
RETURNING id, last_login;
-- Update from another table:
UPDATE orders o
SET status = 'shipped'
FROM shipments s
WHERE s.order_id = o.id AND s.shipped_at IS NOT NULL;