🐘 PostgreSQL
Beginner
How do you update records in PostgreSQL?
Answer
Use the UPDATE statement. Basic form: UPDATE tablename SET column1 = value1, column2 = value2 WHERE condition;. Always include a WHERE clause — omitting it updates every row. Example: UPDATE users SET email = 'new@example.com' WHERE id = 42;. Update with expressions: UPDATE products SET price = price * 1.1 WHERE category = 'electronics';. Update from another table (JOIN): UPDATE orders SET status = 'shipped' FROM shipments WHERE orders.id = shipments.order_id;. Return updated rows: UPDATE users SET active = false WHERE last_login < NOW() - INTERVAL '1 year' RETURNING id, email;.
Previous
What is the difference between INNER JOIN and LEFT JOIN?
Next
How do you delete records in PostgreSQL?