Re: STRING_AGG and GROUP BY

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: STRING_AGG and GROUP BY
Date: 2018-03-16 16:10:02
Message-ID: CAADeyWjAc21emBjQUV0Uv-xWXAhZAmT=L+X1TZV5p5V3zNwqGw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi David -

On Fri, Mar 16, 2018 at 4:40 PM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> ​First reaction is to ARRAY_AGG(DISTINCT x) and then write a function that
> converts ​that array into a string by extracting 'letter' from each cell in
> the array.
>
> Thinking it over a bit you have two columns that both are aggregates but
> that are otherwise independent of each other. Since they are independent
> they cannot be aggregated at the same time. You need to write a two
> subqueries, either in the target list or as separate from/join items, and
> then join the already aggregated queries together on their common group by
> column.
>
> The presence of DISTINCT here (and, IMO, generally), even if it worked,
> would be an indicator that something is not quite right.
>
>
thank you for confirming my feeling that DISTINCT is a bad indicator here...

But you say that "tiles" and "word (score)" are unrelated and this does
not seem true to me:

For each move id aka "mid" there is a JSON value, describing how the player
played the letter tiles.
And for the same "mid" there is a list of one or more "word (score)"s
achieved...

Maybe it is possible to GROUP BY tiles somehow or some kind of special SQL
JOIN?

Regards
Alex

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2018-03-16 16:40:07 Re: STRING_AGG and GROUP BY
Previous Message David G. Johnston 2018-03-16 15:40:00 Re: STRING_AGG and GROUP BY