Contents / Previous / Next


Modifying Data: UPDATE

The UPDATE command allows you to update data already in the database: UPDATE table SET field1=val1, ..., fieldN=valN WHERE condition Tuples in table for which condition is true are updated.
Hence the WHERE clause controls which rows are affected by the UPDATE.

Example:

> UPDATE weather SET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2 WHERE date > '1994-11-28'; new state of the data: > SELECT * FROM weather; city | temp_lo | temp_hi | prcp | date ---------------+---------+---------+------+------------ San Francisco | 46 | 50 | 0.25 | 1994-11-27 San Francisco | 41 | 55 | 0 | 1994-11-29 Hayward | 35 | 52 | | 1994-11-29 (3 rows)