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
expression in ORDER BY clause does match any expression in the SELECT clause (SQL Server) #5470
Comments
any reason you have to use op("+")? there is a mechanism at play that I would have to review in order to describe how it makes its decisions. |
hi can't reproduce locally please share the relevant parts of "Model", e.g. what datattype for columnA as well as requested SQLAlchemy version in use thanks |
Because |
Models class Model(Base):
__tablename__ = 'model'
id = Column(Integer, primary_key=True)
columnA = Column(Numeric(10, 2)) SQLAlchemy version that I used: master |
Mike Bayer has proposed a fix for this issue in the master branch: Allow Grouping to pass along proxy_set of element https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2103 |
Mike Bayer has proposed a fix for this issue in the rel_1_3 branch: Allow Grouping to pass along proxy_set of element https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2104 |
Repaired an issue where the "ORDER BY" clause rendering a label name rather than a complete expression, which is particularly important for SQL Server, would fail to occur if the expression were enclosed in a parenthesized grouping in some cases. This case has been added to test support. Fixes: #5470 Change-Id: Ie0e27c39e5d53be78b32f7810f93d2d0536375e7 (cherry picked from commit 30ec982)
the query above still does not work in 1.3 due to the distinct logic done by Query, seems to not happen in 1.4:
additionally the variant from #5511 doesn't work on either. test for both below
|
The recommended approach to this problem in all cases is to name the label explicitly in your ORDER BY. this will work on all versions, please use this approach:
|
Mike Bayer has proposed a fix for this issue in the master branch: Further fixes for ticket 5470 https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2146 |
Mike Bayer has proposed a fix for this issue in the rel_1_3 branch: Further fixes for ticket 5470 https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2147 |
The fix for #5470 didn't actually take into account that the "distinct" logic in query was also doubling up the criteria. Added many more tests. the 1.3 version here will be different than 1.4 as the regression is not quite the same. Fixes: #5470 Change-Id: I16a23917cab175761de9c867d9d9ac55031d9b97 (cherry picked from commit 7ac2d5c93b6334528aff93939559eee133f3e9fc)
OK that's more fixes. you need to use label(), it won't do the "anon_1" part of it. but all the label() cases should work now. |
Thank you for your prompt fixes. |
Describe the bug
I run the following query on SQL Server
SQLalchemy generates the following query
the query above crashes on SQL Server with
Expected behavior
I expect SQLAlchemy to produce this query instead
Notably, when i replace the
op('+')
method, with the Python operator+
SQLalchemy produces the expected query. That isHave a nice day!
The text was updated successfully, but these errors were encountered: