-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
ENH: Postgres: Provide API for SELECT DISTINCT ON (<column>, <column>, ...) #2008
Comments
I'm going to close this for now. |
Are there any plans on implementing this in the future? |
We are interested in this feature too. 👍 |
For @c-classen we found a workaround at the moment. Ex :
Then, when we want to get entities according to this, we do something like this :
Hope it will help, |
Can you share the exact sql that is being produced and used for this query? |
Re-opening and preparing a PR ... |
Here is the SQL generated by Ebean : select t0.id, t0.last_modifier, [...] from ad t0
where t0.id in (select distinct on (product_id) t0.id from ad t0
where t0.owner_id = any(ARRAY[8])
order by t0.product_id, t0.created_at desc nulls last)
order by t0.created_at desc nulls first limit 20; Note : The inner order by is generated by Ebean because we put order by on both query in our code. Yours faithfully, |
Please review the test cases in the associated PR and confirm it satisfies your use cases for DISTINCT ON queries. |
It seems perfect to our eyes. Yours faithfully, |
We have upgraded to the new version of Ebean and switch our code to this new |
As per ebean-orm-deprecated/ebean-querybean#70
Provide API to support Postgres query extension
SELECT DISTINCT ON (..)
These type of queries run usually a lot faster than the common
e.date = (SELECT max(e2.date) ...)
subquery solution to find the latest event date per city.Proposed API
Similar do
setDistinct(boolean)
Ebean could providesetDistinctOn(<column alias>...)
, e.g.I don't know if Ebean does query checking, but if it does, then it would be worth a warning if both conditions below are not true for such a query. Otherwise the query result will be unpredictable.
The text was updated successfully, but these errors were encountered: