Answer the question
In order to leave comments, you need to log in
How to make pagination with dynamic condition in PostgreSQL?
Hey! There is a large table containing a list of files (chunks that are later glued together (for the sitemap)), their weight and number of lines (changes periodically):
There are 2 variables: ROWS_LIMIT and SIZE_LIMIT It is
required to do pagination using the above conditional variables. \Page\, is considered until the sum of the selected data (rowCount or fileSize rows) hits the set limit.
Is such an implementation possible in pure PostgreSQL?
Answer the question
In order to leave comments, you need to log in
I think window functions will suit you, something like:
WITH
file_list AS (
SELECT id
,SUM(filesize) OVER (PARTITION BY component ORDER BY id) AS filesize_summary
,SUM(rowcount) OVER (PARTITION BY component ORDER BY id) AS rowcount_summary
FROM file_chunks
)
SELECT *
FROM file_chunks c
INNER JOIN file_list l ON c.id=l.id
WHERE TRUE
AND (filesize_summary<=_SIZE_LIMIT OR rowcount_summary<=ROWS_LIMIT);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question