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 than doing 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 name might 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 running DELETE) could be used to identify 
the target partitions and then this list would be used to TRUNCATE all 
resulting partitions.

What does the community think about this?

Thomas


Reply via email to