pg_partman
pg_partman copied to clipboard
[Feature request] create_parent: add an offset in the partitions
Hi,
I needed to create partitions by id, but the first partition starts for id 0 and I needed the first partition to be for id 1, so I suggest adding an offset in the create_parent function to select the first partition, this offset will be a parameter obtained by argument.
In the create_parent function, add a new variable integer called offset initialized to 0 to keep current use, then add the following code on line 576: v_starting_partition_id := v_max - (v_max % v_id_interval); v_starting_partition_id := v_starting_partition_id + offset; FOR i IN 0..p_premake LOOP
Initially I thought the p_start_partition parameter would handle that, but apparently it still started at zero. I'll look into it when I have a chance or if you'd like to make a patch I'd be happy to review it.
I think one issue with this that I'm still unsure of is do you need that offset just for the first partition or do you need that offset to continue forward? Like if the interval was 10, the child tables would normally be spaced like
0 10 20 30
Do you want that offset just for the first table like this?
1 10 20 30
Or for all going forward?
1 11 21 31
If you just want the first one, I honestly don't really see the need for it. While the table may have a lower boundary of 0, that doesn't mean it has to insert that zero value. If that was a concern just for that first child table, you could add a one-off constraint to that first child to prevent it.
If it needs to be a permanent offset for the entire partition set, that I could possibly look into.
My idea was add an offset, because if I want to start the partition, for example with ID 15 and an interval of 10 I would like to get: 15 25 35 Then I solved it adding this: In the create_parent function on line 576: v_starting_partition_id := v_max - (v_max % v_id_interval); v_starting_partition_id := v_starting_partition_id + offset; FOR i IN 0..p_premake LOOP
Ok. Just wanted some clarification. Thanks!
For any question ask me, Thanks in advance
Marking this as a feature to look into for 5.0. If I get a chance to look at it before then I will try.