5.20. PostgreSQL DELETE statement

发布时间 :2025-10-25 12:30:50 UTC      

You can use the DELETE statement to delete the data in the PostgreSQL table.

5.20.1. Grammar

The following is the general syntax for DELETE statements to delete data:

DELETE FROM table_name WHERE [condition];

If not specified WHERE Clause, all records in the PostgreSQL table will be deleted.

In general, we need to WHERE Clause to delete the corresponding record, and the conditional statement can use the AND or OR operator to specify one or more.

5.20.2. Example

Create the COMPANY table ( 下载 COMPANY SQL 文件 ), the data are as follows:

runoobdb# select * from COMPANY;
 id | name  | age | address   | salary
----+-------+-----+-----------+--------
  1 | Paul  |  32 | California|  20000
  2 | Allen |  25 | Texas     |  15000
  3 | Teddy |  23 | Norway    |  20000
  4 | Mark  |  25 | Rich-Mond |  65000
  5 | David |  27 | Texas     |  85000
  6 | Kim   |  22 | South-Hall|  45000
  7 | James |  24 | Houston   |  10000
(7 rows)

The following SQL Statement deletes data with an ID of 2:

runoobdb=# DELETE FROM COMPANY WHERE ID = 2;

The results are as follows:

 id | name  | age | address     | salary
----+-------+-----+-------------+--------
  1 | Paul  |  32 | California  |  20000
  3 | Teddy |  23 | Norway      |  20000
  4 | Mark  |  25 | Rich-Mond   |  65000
  5 | David |  27 | Texas       |  85000
  6 | Kim   |  22 | South-Hall  |  45000
  7 | James |  24 | Houston     |  10000
(6 rows)

As can be seen from the above results, the data with an id of 2 has been deleted.

The following statement deletes the entire COMPANY table:

DELETE FROM COMPANY;

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.