Support DISTINCT ON
See original GitHub issueDISTINCT 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)
SELECT DISTINCT ON
(color)
color,
name,
price
FROM
fruit
ORDER BY price;
query {
fruit(distinct_on: [color], order_by: {price: asc}) {
color
name
price
}
}
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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Fixing DISTINCT ON Not Supported
Fixing DISTINCT ON Not Supported. Ever seen the following error when materializing a view? 1 SELECT DISTINCT ON is not supported. The DISTINCT...
Read more >How to produce same output of "SELECT DISTINCT ON ...
PostgreSQL supports "DISTINCT ON" clause to eliminate rows that match on specified columns/expressions. It's not available on Snowflake, ...
Read more >DISTINCT Clause | ClickHouse Docs
ClickHouse supports using the DISTINCT and ORDER BY clauses for different columns in one query. The DISTINCT clause is executed before the ORDER...
Read more >Add support for select distinct on(a, b, c) - GitHub
The issue in Presto is that on one side, one can't use select distinct on (a, b) c from d but one also...
Read more >MySQL 8.0 Reference Manual :: 8.2.1.18 DISTINCT Optimization
In most cases, a DISTINCT clause can be considered as a special case of GROUP BY . For example, the following two queries...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dmoiseenko Can you try this out on this PR build: https://hge-ci-pull-1099.herokuapp.com/
Note that we force the Postgres restriction that the DISTINCT ON column(s) must match the leftmost ORDER BY column(s).
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.