Postgresql 中文操作指南
2.9. Deletions #
可以使用 DELETE 命令从表中删除行。假设您不再关心海沃德的天气情况。然后,您可以执行以下操作从表中删除这些行:
Rows can be removed from a table using the DELETE command. Suppose you are no longer interested in the weather of Hayward. Then you can do the following to delete those rows from the table:
DELETE FROM weather WHERE city = 'Hayward';
删除属于海沃德的所有天气记录。
All weather records belonging to Hayward are removed.
SELECT * FROM weather;
city | temp_lo | temp_hi | prcp | date
---------------+---------+---------+------+------------
San Francisco | 46 | 50 | 0.25 | 1994-11-27
San Francisco | 41 | 55 | 0 | 1994-11-29
(2 rows)
人们应该警惕以下形式的语句
One should be wary of statements of the form
DELETE FROM tablename;
如果没有限定符,DELETE 将从给定的表格中移除 all 行,留下一个空表格。系统不会在执行此操作之前请求确认!
Without a qualification, DELETE will remove all rows from the given table, leaving it empty. The system will not request confirmation before doing this!