Modifying Rows with UPDATE
Once data has been inserted into rows
within the database, those rows can have one or more of their column values modified through
use of the SQL UPDATE command. Column values may be updated either with
constants, identifiers to other data sets, or expressions. They may apply to an entire column,
or a subset of a column’s values through specified conditions. The UPDATE
command uses the following syntax:
UPDATE [ ONLY ] table SET column = expression [, ...] [ FROM source ] [ WHERE condition ]
UPDATE [ ONLY ]tableThe
ONLYkeyword may be used to indicate that only the tabletableshould be updated, and none of its sub-tables. This is only relevant iftableis inherited by any other tables.SETcolumn = expression[, ...]The required
SETclause is followed by an update expression for each column name that needs to have its values modified, separated by commas. This expression is always of the formcolumn = expression,wherecolumnis the name of the column to be updated (which may not be aliased, or dot-notated), and whereexpressiondescribes the new value to be inserted into the column.FROMsourceThe
FROMclause is a non-standard PostgreSQL extension that allows table columns from other data sets to update a column’s value.WHEREconditionThe
WHEREclause describes theconditionupon which a row intablewill be updated. If unspecified, all values incolumnwill be modified. This may be used to qualify sources in theFROMclause, as you would in aSELECTstatement. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access