changed mysql db to postgres. changed group by queries to distinct on.