How to PostgreSQL- Update & Delete Query

This PostgreSQL tutorial explains how to use the UPDATE & DELETE Query  Statements with syntax and examples. PostgreSQL UPDATE command will modify any field value of any PostgreSQL table. The DELETE statement is used to delete records from a table.


PostgreSQL UPDATE Statement

The PostgreSQL UPDATE statement is used to change or modify the existing records in a database table. It is typically used in conjugation with the WHERE clause to apply the changes to only those records that match specific criteria. The basic syntax of UPDATE query with WHERE clause is as follows:


     UPDATE table_name
     SET column1 = value1, column2 = value2, ... 
     WHERE [condition];


column1, column2: Name of column(s) to be updated.
value1, value2: New value(s).
WHERE conditions are used to filter the rows returned from the UPDATE statement.

Consider the table payroll having following records:



PostgreSQL Update & Delete Query


The following example updates the designation of a payroll record in the payroll table that matches firstname=’Habeeb’ and lastname=’Rahman’.


    UPDATE payroll
    SET designation = 'Administrator' 
    WHERE firstname = 'Habeeb' AND lastname = 'Rahman';



postgresql Update & delete query


PostgreSQL DELETE Statement

The PostgreSQL DELETE statement is used to delete a single record or multiple records from a table. You can use WHERE clause with DELETE query to delete selected rows, otherwise, all the records would be deleted. The following is a basic syntax of DELETE query with WHERE clause.


     DELETE FROM table_name
     WHERE [condition];
     DELETE FROM payroll
     WHERE lastname = 'Yakkiparamban' AND firstname = 'Anwar';


This above example would delete a record from the payroll table where the lastname is Yakkiparamban and firstname is Anwar.



postgresql Update & delete query

Anwar Yakkiparamban

Anwar Yakkiparamban is the founder of Lauyou Learning. Prior to Lauyou learning, Anwar worked at ARD Engineering & Development, Qatar. He holds bachelor degree in Electronics and Communication Engineering from Govt. Engineering College Idukki.

You may also like...