postgresql


UPDATE All Versions

8.0
8.1
8.2
8.3
8.4
9.0
9.1
9.2
9.3
9.4
9.5

This draft deletes the entire topic.

inline side-by-side expand all collapse all

Examples

I am downvoting this example because it is...

Syntax

Syntax

Parameters

Parameters

Remarks

Remarks

Still have question about UPDATE? Ask Question

Update all rows in a table

0

You update all rows in table by simply providing a column_name = value:

UPDATE person SET planet = 'Earth'

Update all rows meeting a condition

0
UPDATE person SET state = 'NY' WHERE city = 'New York'

Updating a table based on joining another table

0

You can also update data in a table based on data from another table:

UPDATE person 
SET state_code = cities.state_code 
FROM cities
WHERE cities.city = city

Here we are joining the person city column to the cities city column in order to get the city's state code. This is then used to update the state_code column in the person table.

Updating multiple columns in table

0

You can update multiple columns in a table in the same statement, separating col=val pairs with commas:

UPDATE person SET country = 'USA', state = 'NY' WHERE city = 'New York'

Topic Outline