Suggestion: provide a "TRUNCATE PARTITION" command - Mailing list pgsql-general

From Thomas Kellerer
Subject Suggestion: provide a "TRUNCATE PARTITION" command
Date
Msg-id 99277f39-f1a1-6da5-176c-3def058cf568@gmx.net
Whole thread Raw
Responses Re: Suggestion: provide a "TRUNCATE PARTITION" command  (legrand legrand <legrand_legrand@hotmail.com>)
Re: Suggestion: provide a "TRUNCATE PARTITION" command  (Michael Lewis <mlewis@entrata.com>)
List pgsql-general
Hello,

I wonder if it made sense to add a "TRUNCATE PARTITION" command to Postgres?

Especially during bulk loads it's more efficient to TRUNCATE a partition if I know I want to replace all rows, rather
thandoing a DELETE.
 

Currently this requires dynamic SQL which isn't always feasible (and might get complicated quickly).

So I was thinking that a new command to allow truncating partitions by identifying the partitions by "value" rather by
namemight be helpful in that case.
 

Something along the lines of:

     truncate partitions of base_table
     for values in (...);

If the IN part allowed for sub-queries then this could be used to gather the partition keys from e.g. a staging table.
In my naive understanding, I would think the current partition pruning code (e.g. that picks the partitions when
runningDELETE) could be used to identify the target partitions and then this list would be used to TRUNCATE all
resultingpartitions.
 

What does the community think about this?

Thomas



pgsql-general by date:

Previous
From: 徐閔翊 Jordy Hsu
Date:
Subject: Coding question
Next
From: Tim.Colles@ed.ac.uk
Date:
Subject: Re: How to keep format of views source code as entered?