Updating Data in PostgreSQL

What is Updating Data in PostgreSQL?

Updating data in an SQL database table is changing (aka modifying) values in all, some or one of the already existing table cells of a given column or given columns.

Updating All Cells of a Given Column

It is possible to update all cells of a given column simultaneously.

UPDATE users
SET role = 'client';

The above command updates the role column in all rows of the table users to the string 'client'.

Updating Only Specific Cells of a Given Column

It is possible to update only cells belonging to rows meeting specific criteria. The criteria (conditions) are provided using the keyword WHERE appended with a boolean expression which can reference the updated table columns.

UPDATE horses
SET free_roaming = TRUE
WHERE status = 'mustang';

The above command updates the column free_roaming to TRUE for all rows in the table horse where status equals mustang. The remaining rows remain unaffected.

UPDATE users
SET role = 'admin'
WHERE id = 42;

The above command updates the column role in only the row with the id of 42.

We use cookies and similar technologies to enhance the quality of services, maintain statistics and adjust marketing content. You will find more information in the Cookies Policy.

By clicking OK you grant consent to processing of your personal data by us and our Trusted Partners with the purpose of maintain statistics and adjustment of the marketing content pursuant to the Privacy Policy. If you wish to not grant that consent and/or limit its extent click Settings.