In my project I have a db table with ~8M records. Every record contains an integer
create table blocks(id bigserial, width int); insert into blocks(width) values (1),(2),(6),(3),(3),(3),(2),(5),(4),(2);
Frontend part displays all these blocks in a single extremely long web page which loads dynamically on scroll. Widths from the above would fit into a view with its own width equal to 10 like that:
0: 1, 2, 6 1: 3, 3, 3 2: 2, 5 3: 4, 2
The sum of widths of elements on a single line must be less or equal to the line width. So, for now I have a list of tables of line offsets for a query on the app's side, for example, for
line width == 10:
0: 0 1: 3 2: 6 3: 8
I'd like to create a temporary table at the moment of cursor opening but cannot get how to calculate and build it. It must utilize line width parameter and probably should use rolling sum, but I am unlucky with writing the sql statement.
UPD: I found exactly the same question on dba.stackexchange.com , but the answer there is incorrect, I left a comment under it.