Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



24.1k
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