pgsql 删除分区表
时间: 2023-09-11 21:05:09 浏览: 160
通过在pgSQL版本10中引入声明式分区表,可以实现删除分区表。可以使用以下函数来删除分区表:
```sql
CREATE OR REPLACE FUNCTION deletePartitionIfExists (tb_name_partiton_val VARCHAR) RETURNS VOID AS $body$
DECLARE
master_name TEXT := tb_name_partiton_val; -- 删除分区表表名
BEGIN
-- 判断分区名称是否存在,不存在时才需要创建
IF to_regclass (tb_name_partiton_val) IS NOT NULL THEN
-- 执行删除分区
EXECUTE format ('DROP TABLE %s', tb_name_partiton_val);
END IF;
END;
$body$ LANGUAGE plpgsql;
```
这个函数接受分区表的名字作为参数,并通过执行`DROP TABLE`语句来删除分区表。如果分区表不存在,则不会执行删除操作。这样就可以实现删除pgSQL的分区表。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [pgsql在分区表与非分区表中自由切换](https://blog.csdn.net/zjcxc/article/details/120239954)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [postgre sql 将非分区表转化为分区表,动态创建和删除分区](https://blog.csdn.net/qq_41982570/article/details/126878258)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [PostgreSQL表分区和子表及删除所有的数据库表.zip](https://download.csdn.net/download/as4589sd/12169679)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文