Search Postgresql Archives

Re: STRING_AGG and GROUP BY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi David -

On Fri, Mar 16, 2018 at 4:40 PM, David G. Johnston <david.g.johnston@xxxxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux