Answer the question
In order to leave comments, you need to log in
How to get all data from a row in a given query?
Have a request
WITH RECURSIVE
r AS (
SELECT array[]::bigint[] AS res,min(id) AS min, max(id)-min(id) AS range FROM items
UNION ALL
SELECT res||ARRAY(SELECT id FROM items WHERE id IN (SELECT (min+range*random())::int FROM generate_series(1,${custom.numRows})) AND NOT id=ANY(res)), min, range
FROM r
WHERE
coalesce(array_length(res,1),0)<${custom.numRows}
)
SELECT * FROM (
SELECT res FROM r ORDER BY array_length(res,1) DESC NULLS LAST LIMIT 1
) AS t LIMIT ${custom.numRows};
{ res: [ '4146' ] }
WITH RECURSIVE
r AS (
SELECT array[]::bigint[] AS res,min(id) AS min, max(id)-min(id) AS range FROM items
UNION ALL
SELECT res||ARRAY(SELECT id FROM items WHERE id IN (SELECT (min+range*random())::int FROM generate_series(1,${custom.numRows})) AND NOT id=ANY(res)), min, range
FROM r
WHERE
coalesce(array_length(res,1),0)<${custom.numRows}
)
SELECT * FROM items WHERE id IN (
SELECT res FROM r ORDER BY array_length(res,1) DESC NULLS LAST LIMIT 1
) LIMIT ${custom.numRows}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question