Skip to main content

UPDATE

The UPDATE statement modifies the values of columns in existing rows of a table.

Syntax

Description

UPDATE changes column values in rows that match the WHERE condition. If no WHERE clause is provided, all rows in the table are updated.

Conflict Handling

The optional OR clause specifies how to handle constraint violations during the update. When omitted, the default behavior is ABORT.

SET Clause

The SET clause assigns new values to one or more columns. Each assignment consists of a column name, an equals sign, and an expression. The expression can reference other columns of the same row, and it sees the original (pre-update) values of all columns.
Multiple columns can also be set using a parenthesized column list:

FROM Clause

The FROM clause allows the UPDATE to reference other tables. Columns from the joined tables can be used in SET expressions and the WHERE clause. This is useful for updating a table based on matching rows from another table.
When the target table also appears in the FROM clause, it refers to a second instance of that table that can be used for self-joins.

WHERE Clause

The WHERE clause restricts which rows are updated. Only rows where the expression evaluates to true are modified. If the WHERE clause is omitted, every row in the table is updated.

RETURNING Clause

The RETURNING clause causes the UPDATE statement to return the new values of each modified row. The result columns can be expressions referencing the updated column values.

ORDER BY and LIMIT

The ORDER BY and LIMIT clauses restrict which rows are updated. ORDER BY determines the order in which rows are considered, and LIMIT caps the number of rows that are actually modified. ORDER BY requires LIMIT to be present.
LIMIT accepts an optional OFFSET to skip a number of rows before applying the limit:

Examples

Update rows matching a condition

Update using a join with FROM

Update with RETURNING

See Also