--- /dev/null
+.. change::
+ :tags: bug, sql
+ :tickets: 5470
+
+ 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.
+
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
+from sqlalchemy import testing
from sqlalchemy import text
from sqlalchemy import union
from sqlalchemy import util
"FROM mytable AS mytable_1 ORDER BY mytable_1.name",
)
+ @testing.combinations(
+ ((column("q") + 5).label("a"), "a", ()),
+ (column("q").op("+")(5).label("a"), "a", ()),
+ ((column("q") + 5).label("a"), "a DESC", (desc,)),
+ (column("q").op("+")(5).label("a"), "a DESC", (desc,)),
+ )
+ def test_order_by_expr(self, case, expected, modifiers):
+
+ order_by = case
+ for mod in modifiers:
+ order_by = mod(order_by)
+
+ stmt = select([case]).order_by(order_by)
+
+ col_expr = str(case)
+ self.assert_compile(
+ stmt, "SELECT %s AS a ORDER BY %s" % (col_expr, expected)
+ )
+
def test_order_by_named_label_from_anon_label(self):
s1 = select([table1.c.myid.label(None).label("foo"), table1.c.name])
stmt = s1.order_by("foo")