New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support DISTINCT ON #1040
Comments
TODO:- Add tests and docs
@dmoiseenko Can you try this out on this PR build: https://hge-ci-pull-1099.herokuapp.com/ {
product(distinct_on: color order_by: {color: asc price:desc}) {
id
price
color
}
} Note that we force the Postgres restriction that the DISTINCT ON column(s) must match the leftmost ORDER BY column(s). |
@0x777 |
Thanks for the insight @0x777 |
Hi, I know this has been closed already, but is it supposed to work with multiple columns like the postgres query does? I can only use it for a single column |
Hi @cleivson, please note that this issue was related to Postgres. By the time this was closed, we only support single Postgres source (version 1.x). Thank you. |
you use [] to specify multiple columns. You can't do it with the graphiql editor.
That's not at all what he was asking @rakeshkky he wanted to know about multiple columns in a distinct clause. |
DISTINCT ON is a really powerful Postgres feature to perform aggregation-like(pick first in group). It can be used in plain SELECT queries without window function or GROUP BY.
It will be great to see support of DISTINCT ON since Hasura has excellent support of ORDER BY.
e.g.
We need to get the cheapest fruits in groups by color(see sudo SQL<=>GraphQL below)
Postgres documentation https://www.postgresql.org/docs/11/sql-select.html#SQL-DISTINCT
Usage example https://medium.com/statuscode/the-many-faces-of-distinct-in-postgresql-c52490de5954
The text was updated successfully, but these errors were encountered: