]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Turned off the "simple order by" flag on the MSSQL dialect; this
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Mar 2015 16:28:19 +0000 (12:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Mar 2015 16:28:19 +0000 (12:28 -0400)
is the flag that per :ticket:`2992` causes an order by or group by
an expression that's also in the columns clause to be copied by
label, even if referenced as the expression object.   The behavior
for MSSQL is now the old behavior that copies the whole expression
in by default, as MSSQL can be picky on these particularly in
GROUP BY expressions.
fixes #3338
- Add a test that includes a composed label in a GROUP BY

doc/build/changelog/changelog_10.rst
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/testing/suite/test_select.py

index 3bcb4d6cfcb7b3ffc58720609e1845e6b43bf427..281092ae12b9dfcd23e61f11921af000f4de3bc5 100644 (file)
 .. changelog::
     :version: 1.0.0b4
 
+    .. change::
+        :tags: bug, mssql
+        :tickets: 3338
+
+        Turned off the "simple order by" flag on the MSSQL dialect; this
+        is the flag that per :ticket:`2992` causes an order by or group by
+        an expression that's also in the columns clause to be copied by
+        label, even if referenced as the expression object.   The behavior
+        for MSSQL is now the old behavior that copies the whole expression
+        in by default, as MSSQL can be picky on these particularly in
+        GROUP BY expressions.
+
     .. change::
         :tags: feature, schema
         :tickets: 3341
index ea0ed58a444798786d732ecec45a81f0242671ab..26b7947120f2007b1879106533c0c0878c57277c 100644 (file)
@@ -1416,6 +1416,7 @@ class MSDialect(default.DefaultDialect):
     use_scope_identity = True
     max_identifier_length = 128
     schema_name = "dbo"
+    supports_simple_order_by_label = False
 
     colspecs = {
         sqltypes.DateTime: _MSDateTime,
index 68dadd0a9144fbd3d537b49f72cd6dff89222935..ecc92b884b1efedf7e19b3dbc69961d7c109426d 100644 (file)
@@ -86,6 +86,15 @@ class OrderByLabelTest(fixtures.TablesTest):
             [(7, ), (5, ), (3, )]
         )
 
+    def test_group_by_composed(self):
+        table = self.tables.some_table
+        expr = (table.c.x + table.c.y).label('lx')
+        stmt = select([func.count(1), expr]).group_by(expr).order_by(expr)
+        self._assert_result(
+            stmt,
+            [(1, 3), (1, 5), (1, 7)]
+        )
+
 
 class LimitOffsetTest(fixtures.TablesTest):
     __backend__ = True