PostgreSQL – Update data in a Table

The PostgreSQL UPDATE statement can be used to modify existing records in a table. The basic syntax of the UPDATE statement is as follows:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE conditions;
  • table_name: The name of the table that you want to update records in.
  • column1, column2, etc.: The names of the columns that you want to update.
  • value1, value2, etc.: The new values that you want to set for the columns.
  • condition: The condition that specifies which records to update.

Below is an example to demonstrates the usage of the UPDATE statement:

Consider a table named “employees” with the following columns: employee_id, name, email, salary. And we want to update the salary of the employee with employee_id 1 to $50000.

UPDATE employees
SET salary = 50000
WHERE employee_id = 1;

Above sql statement will update the salary column of the employee with employee_id 1 to $50000. If the WHERE clause is omitted, the UPDATE statement will modify all the records in the table.

Similar Posts