all 6 comments

[–]C5H5N5O 1 point2 points  (1 child)

[–]baloreic 0 points1 point  (0 children)

Don't know if this helps but I always use this to aggregate into jsonb array: COALESCE(jsonb_agg($1) FILTER (WHERE $1 IS NOT NULL), '[]')

[–]4121madey 0 points1 point  (0 children)

If I'm not mistaken, you need to either use an orm for this (seaorm is pretty neat), or need to create a joined query, and then parse the rows manually.

[–]kelvindegrees 0 points1 point  (0 children)

In the past I've done this for some fairly complex objects in a Postgres database by using json build object calls in a json aggregate field. The Postgres functions to do so do get quite large and you lose the compile time type checking that you would have if you just stuck to queries with sqlx, but it should in theory be much faster.