DROP INDEX
是一个用于移除索引的 DDL 命令。
DROP INDEX
一直存在于 PostgreSQL 中。
变更历史
- PostgreSQL 9.2
- 添加了
DROP INDEX CONCURRENTLY
语法(提交 8cb53654)
- 添加了
- PostgreSQL 8.2
- 添加了
DROP INDEX IF EXISTS ...
语法(提交 daea4d8e)
- 添加了
- PostgreSQL 7.3
- 添加了
CASCADE
和RESTRICT
子句(提交 7c6df91d)
- 添加了
- PostgreSQL 7.1
- 可以使用同一个
DROP INDEX
命令移除多个索引(提交 9ace0318)
- 可以使用同一个
示例
DROP INDEX
的基本执行示例
postgres=# DROP INDEX ocr_uripart_ix; DROP INDEX
安全地尝试删除可能不存在的索引
postgres=# DROP INDEX IF EXISTS foo; NOTICE: index "foo" does not exist, skipping DROP INDEX
尝试删除与约束关联的索引
postgres=# DROP INDEX category_pkey; ERROR: cannot drop index category_pkey because constraint category_pkey on table category requires it HINT: You can drop constraint category_pkey on table category instead.
参考资料
- PostgreSQL 文档: DROP INDEX