w3resource

Eliminate the 2023 Sales Partition from the Table


Dropping a Partition from a Partitioned Table

Write a PostgreSQL query to drop the Sales_2023 partition.

Solution:

-- Drop the 2023 sales partition.
DROP TABLE Sales_2023;

Explanation:

  • Purpose of the Query:
    • Removes a specific partition while keeping the parent table.

Notes:

  • Be cautious, as this action permanently deletes the partition's data.

For more Practice: Solve these Related Problems:

  • Write a PostgreSQL query to drop a specific partition from a range-partitioned table after archiving its data to a backup table.
  • Write a PostgreSQL query to drop multiple partitions from a list-partitioned table within a single transaction.
  • Write a PostgreSQL query to safely drop a hash partition from a partitioned table and log the deletion in an audit table.
  • Write a PostgreSQL query to drop a partition from a partitioned table and verify that the parent table remains intact without data loss.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous PostgreSQL Exercise: Querying Data from a Partitioned Table.

Next PostgreSQL Exercise: Adding a Default Partition.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.