Re: Multiple Aggregations Order

2020-01-14 Thread João Haas
I also thought about that. The 'issue', is that when you call array_agg in a row/type, it casts the entire thing in a string. But some of the aggregation fields are jsonb fields, which are also casted to strings, with extra escapes. Then, I'm also using Django, which seems to mess the string even m

Re: Multiple Aggregations Order

2020-01-14 Thread Thomas Kellerer
João Haas schrieb am 14.01.2020 um 18:26: I'm working on a query where I need to fetch information from a table along with some data from a many-to-many connection table in a single query. My idea is to do an outer join with the connection query and aggregate the needed data in multiple 'array_ag

Re: Multiple Aggregations Order

2020-01-14 Thread João Haas
I'm aiming to serialize some graph data into a JSON format, and some of the data needed for the serialization is in the relation tables, like, "this node connects to this other node in this way". These are served to IOT devices and the data changes a lot, so there's a ton of requests and caching is

Re: Multiple Aggregations Order

2020-01-14 Thread David G. Johnston
On Tuesday, January 14, 2020, João Haas wrote: > > SELECT tb.*, array_agg(conn.child_id), array_agg(conn.kind) > > Create a custom type (using row(...) might work...?) with the relevant fields and “...array_agg((child_id, kind)::custom_type order by ...”? David J.

Re: Multiple Aggregations Order

2020-01-14 Thread Michael Lewis
"handle this aggregated data later in code" What is your end goal though? Also, approx how many rows in these tables? Can you share an example query and plan? What version are you using? >

Multiple Aggregations Order

2020-01-14 Thread João Haas
Hi there, I'm working on a query where I need to fetch information from a table along with some data from a many-to-many connection table in a single query. My idea is to do an outer join with the connection query and aggregate the needed data in multiple 'array_agg's, and then handle this aggrega