E
E
EVOSandru62015-09-09 15:11:02
PostgreSQL
EVOSandru6, 2015-09-09 15:11:02

How to perform partitioning in postgres if the number of possible slave tables is not known?

Good afternoon.
There is such a table:
---------
parts
---------
id
value

---------
The table is filled with records:
id value
1 40
2 1000

------ ---------
3 500
4 2
5 13
6 860

--------------
7 74
8 15
9 230

------------- -
10 100
-------------- It is
necessary to perform partitioning according to the following condition:
The maximum value in the table is taken ( 1000 ) . The first segment is taken from the first record up to this maximum valueinclusive.
Then the algorithm repeats, the next maximum number is 860 , this segment will start from 500 , because 100 is already filled and 860 each .
And this algorithm should be repeated (recursively?!) until there are no records left in the main table that are free for further partitioning.
As a result, the following groups should be obtained:
1 group - 40, 1000
2 group - 500, 2, 13, 860
3 group - 74, 15, 230
4 group - 100
I was able to solve this in php by pulling out an array, but it is necessary to divide it in postgres by slavetables, provided that the parts table can be infinite, i.e. subtables must be created dynamically.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question