How to select all rows to json in postgresql
SELECT row_to_json(r) record FROM
(
SELECT * FROM records
ORDER BY record_id ASC
) r;
With a common table expression
WITH records_cte AS (
SELECT * FROM records
ORDER BY record_id SC
) SELECT row_to_json(records_cte)
FROM records_cte;