Delete a partitioned table
Updated at:
DROP TABLE permanently removes a partitioned table and all of its partitions from the database. DROP TABLE also deletes all indexes, rules, triggers, and constraints associated with the table. To clear rows without removing the table, use DELETE or TRUNCATE instead.
DROP TABLE in PolarDB for PostgreSQL is fully compatible with PostgreSQL. For the complete reference, see the PostgreSQL documentation.
Prerequisites
Only the table owner, schema owner, or superuser can drop a table.
Syntax
DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]Parameters
| Parameter | Description |
|---|---|
IF EXISTS | Drop the table only if it exists. If the table does not exist, no error is returned. |
name | The name of the table to drop. To drop multiple tables in a single statement, separate the names with commas. |
CASCADE | Drop all objects that depend on the table, such as views and foreign key constraints. |
RESTRICT | (Default) Refuse to drop the table if any dependent objects exist. |
Examples
Drop a single partitioned table
DROP TABLE tab_range;Drop a table only if it exists
Use IF EXISTS to avoid errors in scripts when the table may not be present.
DROP TABLE IF EXISTS tab_range;Drop multiple partitioned tables
DROP TABLE tab_range, tab_list;Drop a table with dependent views
If a view or foreign key constraint references the table, use CASCADE.
DROP TABLE tab_range CASCADE;Is this page helpful?