Re: Multiple Aggregations Order

João Haas <[email protected]> Tue, 14 Jan 2020 18:17:22 -0300
Newsgroups gmane.comp.db.postgresql.general
Message-ID <CAEi5ktJe0W1fTX2Xo97+xCAhU8=TBqDQx4VwM0vqvH8CNLOURg@mail.gmail.com>
--000000000000d104d9059c201e7d
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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 more. I could try to denormalize this whole mess, but I don't think
the overhead of sorting each agg is enough for this. Also, Django handles
these extra fields really well on raw queries, so it's not an issue having
a lot of fields.

On Tue, Jan 14, 2020 at 5:43 PM David G. Johnston <
[email protected]> wrote:

> On Tuesday, January 14, 2020, Jo=C3=A3o Haas <[email protected]> wro=
te:
>>
>> SELECT tb.*, array_agg(conn.child_id), array_agg(conn.kind)
>>
>>
> Create a custom type (using row(...) might work...?) with the relevant
> fields and =E2=80=9C...array_agg((child_id, kind)::custom_type order by .=
..=E2=80=9D?
>
> David J.
>

--000000000000d104d9059c201e7d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I also thought about that. The &#39;issue&#39;, is that wh=
en 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&#39;m also using Django, which see=
ms to mess the string even more. I could try to denormalize this whole mess=
, but I don&#39;t think the overhead of sorting each agg is enough for this=
. Also, Django handles these extra fields really well on raw queries, so it=
&#39;s not an issue having a lot of fields.</div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Jan 14, 2020 at 5:43 PM =
David G. Johnston &lt;<a href=3D"mailto:[email protected]">david.g=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)=
;padding-left:1ex">On Tuesday, January 14, 2020, Jo=C3=A3o Haas &lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
</a>&gt; wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=
=3D"ltr"><font face=3D"monospace">SELECT tb.*, array_agg(conn.child_id), ar=
ray_agg(conn.kind)<br><br></font></div><div dir=3D"ltr"></div></blockquote>=
<div><br></div><div>Create a custom type (using row(...) might work...?) wi=
th the relevant fields and =E2=80=9C...array_agg((child_id, kind)::custom_t=
ype order by ...=E2=80=9D?</div><div><br></div><div>David J.</div>
</blockquote></div>

--000000000000d104d9059c201e7d--