diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2017-01-09 14:25:13 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit@awstats.zzzcomputing.com> | 2017-01-09 14:25:13 -0500 |
commit | e6eefc0c5e946f10cb31264d71d6f1987a3f96e8 (patch) | |
tree | 43bcd77ef4ff66907bde17117cdfd7b3d5fff927 /test/sql/test_compiler.py | |
parent | bc4a96836d5bfb911da26f7e77119f3a7b356f2e (diff) | |
parent | 6b489db89970b1fcec38a7c3772960ed3291a2ed (diff) | |
download | sqlalchemy-e6eefc0c5e946f10cb31264d71d6f1987a3f96e8.tar.gz |
Merge "Tighten rules for order_by(Label) resolution"
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r-- | test/sql/test_compiler.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index a85786bed..38ca09c0a 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -952,6 +952,56 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect=dialect ) + # expression isn't actually the same thing (even though label is) + self.assert_compile( + select([lab1, lab2]).order_by( + table1.c.myid.label('foo'), + desc(table1.c.name.label('bar')) + ), + "SELECT mytable.myid + :myid_1 AS foo, " + "somefunc(mytable.name) AS bar FROM mytable " + "ORDER BY mytable.myid, mytable.name DESC", + dialect=dialect + ) + + # it's also an exact match, not aliased etc. + self.assert_compile( + select([lab1, lab2]).order_by( + desc(table1.alias().c.name.label('bar')) + ), + "SELECT mytable.myid + :myid_1 AS foo, " + "somefunc(mytable.name) AS bar FROM mytable " + "ORDER BY mytable_1.name DESC", + dialect=dialect + ) + + # but! it's based on lineage + lab2_lineage = lab2.element._clone() + self.assert_compile( + select([lab1, lab2]).order_by( + desc(lab2_lineage.label('bar')) + ), + "SELECT mytable.myid + :myid_1 AS foo, " + "somefunc(mytable.name) AS bar FROM mytable " + "ORDER BY bar DESC", + dialect=dialect + ) + + # here, 'name' is implicitly available, but w/ #3882 we don't + # want to render a name that isn't specifically a Label elsewhere + # in the query + self.assert_compile( + select([table1.c.myid]).order_by(table1.c.name.label('name')), + "SELECT mytable.myid FROM mytable ORDER BY mytable.name" + ) + + # as well as if it doesn't match + self.assert_compile( + select([table1.c.myid]).order_by( + func.lower(table1.c.name).label('name')), + "SELECT mytable.myid FROM mytable ORDER BY lower(mytable.name)" + ) + def test_order_by_labels_disabled(self): lab1 = (table1.c.myid + 12).label('foo') lab2 = func.somefunc(table1.c.name).label('bar') |