PostgreSQL Delete query is used to delete records from the table. If we supply the where clause then it will delete the specific rows and in case the where clause is omitted then the complete records are deleted and the empty table is left. To perform the delete operation, we should have the Delete table permission present on the object.

The syntax of Delete Query is as mentioned below.


DELETE FROM tablename WHERE [condition];

1. Delete Query With Where Clause

We have created a table named PRODUCTS_DETAIL and it has mentioned values, Now we will use the DELETE query to delete the records where the PRODUCT_NUMBER is 101.


postgres=# DELETE FROM PRODUCTS_DETAIL WHERE product_number=101;


From the below output, we can see that row 101 of the column PRODUCT_NUMBER has been deleted.

postgresql delete command with where cluase

2. Delete Query Without Where Clause

The Delete Query without where clause will delete all records from the table and left the table empty. It should be avoided unless required. In this section, we will use the Delete query without mentioning the where clause to delete all records from the table PRODUCTS_DETAIL.




All records from the table PRODUCTS_DETAIL have been deleted as we can see in the below output.

postgresql delete all records