Thursday, March 30, 2017

Mysql(GroupBy) alternative for Postgresql?

I am using laravel with mysql..

I have query something like this..

$mix = Ergebnisse::where(function($q) use($result) {               
    foreach ($result as $item) {
         $q->orWhere(function($q) use($item) {
             $q->where('temperatur', $item->temperatur)
               ->where('zeit', $item->zeit);
        });
    }
})->groupBy('katogorie_id')->get();

on my localhost it is working fine as i am using mysql there. but i deployed the project on Heroku with Postgresql.

I got an error..

SQLSTATE[42803]: Grouping error: 7 ERROR: column "ergebnisse.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select * from "ergebnisse" where (("temperatur" = $1 and "ze...
^ (SQL: select * from "ergebnisse" where (("temperatur" = 85 and "zeit" = 35) or ("temperatur" = 85 and "zeit" = 30)) group by "katogorie_id")

after further searching i came to know that GroupBy is not compatible with postgre. is there any other way of doing that? thanks



via Hassan Haroon

Advertisement