Build
jsonb_build_object makes an object. jsonb_agg collects rows into an array, and takes an ORDER BY.
task
Each order as one JSON object {id, lines: [{p, q}]}, lines in line_no order.
Run a query to see rows here.
Run EXPLAIN on the statement under the cursor: Plan tab, button Explain.
No tables yet.
jsonb_build_object makes an object. jsonb_agg collects rows into an array, and takes an ORDER BY.
Each order as one JSON object {id, lines: [{p, q}]}, lines in line_no order.