Book Contents

Book Index

Next Topic

Home

UPDATE

UPDATE replaces the values of the specified columns in all rows for which a specific condition is true. All other columns and rows in the table are unchanged.

Syntax

UPDATE table SET column = { expression | DEFAULT } [, ...]

[ FROM from-list ]

[ WHERE clause ]

Semantics

table

specifies the name of a table in the schema. You cannot UPDATE a projection.

column

specifies the name of a non-key column in the table.

expression

specifies a value to assign to the column. The expression can use the current values of this and other columns in the table. For example:

UPDATE T1 SET C1 = C1+1;

from-list

A list of table expressions, allowing columns from other tables to appear in the WHERE condition and the update expressions. This is similar to the list of tables that can be specified in the FROM Clause of a SELECT command. Note that the target table must not appear in the fromlist.

Notes

Examples

UPDATE FACT SET PRICE = PRICE - COST * 80 WHERE COST > 100;

UPDATE CUSTOMER SET STATE = 'NH' WHERE CID > 100;

SQL Language References

PostgreSQL 8.0.12 Documentation

BNF Grammar for SQL-99