You are viewing a single comment's thread from:

RE: Foooking can't grok GroupBy in Postgres

in #postgres2 months ago

Yup, Eloquent from Laravel which I think is the part that kinda made me insist it can be done the way I want. Since there is the groupBy method for the ORM but also groupBy for result object. The groupBy on the result object does exactly what I showed and keys the results accordingly, where as the groupBy on the ORM or query builder is an interface for the SQL engines methods and in POSTGRES you have to have all columns from the select available in the groupBy + then any aggregates you use can be excluded so counting etc works but if I wanted all the data the best is to use the result and instead groupBy in my code to build the structure I want.

Sort:  

I think I understand, it just seems ugly to re-execute one query after another to recover the missing data

Yes which is why I was pretty determined to get it in one go but for this case specifically I did not really need the extra data. If I did I think I would query the rows as normal and instead of having sql do the computing just run a loop to structure it as I want it , which is actually what I usually do. Guess it depends what I am querying, I will learn better ways to do it as I go I am sure :) !PIZZA