-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SELECT DISTINCT ON expressions must match initial ORDER BY expressions #495
Comments
@ericmj what if we automatically set the order_by when we set the distinct? Or we introduce something like |
@josevalim Yes, but it also seems like we should try to converge when the same expression is interpolated twice to a single query parameter. |
@ericmj how should we do it though? check for equality in the params as we merge them? Unfortunately it doesn't work for database like mysql. should it be a postgres connection optimization? |
I didn't consider mysql so lets table that. It's useful for optimization but not for anything else. |
@ericmj should we then change the postgres adapter to automatically add what is in distinct to order_by? |
I'm not sure, maybe it should be explicit? Should we do it by default even though Postgres doesn't? |
I am not sure. We will definitely have issues like above AND there is no work around. Hardcoding to $1 is brittle. :( |
I think we should give it a go at automatically copying. Let's just make it explicit in the docs. So this is now ready for tackling. /cc @briksoftware @whatyouhide |
I'd like to take this one on. Expect a PR in the next 24 hours. :) |
I encounter the error
SELECT DISTINCT ON expressions must match initial ORDER BY expressions
for a query that looks like this:
Which outputs the following query in Postgres:
It works when I change the query to:
I just hardcode
$1
to the above query so the output query in Postgres is:The text was updated successfully, but these errors were encountered: