We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Select Distinct ON Postgres

Hello, it's possible to do a Select Distinct ON(field), since query builder->distinct() accept only null or bool,

I need to use it to avoid user GroupBy Grouping error: 7 ERROR: column "field" must appear in the GROUP BY clause or be used in an aggregate function

Thanks

This is for Last Phalcon and Postgresql 10



32.2k
Accepted
answer

It's an limitation. You have to create a NFR in github. If you want, you can create the solution too ;)

I just want to know if there as a native way, about the creation, look's like the only way is to do it.

thanks,

Well you can use raw way

\Phalcon\Di::getDefault()->getShared('db')->query(
    'select distintct * from robots`where name != {name:str} and year > {year:int}',
    [
        'name' => 'Astro Boy',
        'year' => 1952,
    ]
);

I don't know if you can improbe this with dialect

Good luck