diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-13 18:21:42 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-13 18:21:42 -0400 |
commit | 1ac57f0b52e3e89097129931d46ebbbb39ee7927 (patch) | |
tree | 548f6e6982fa3501d6b5a5cf7abd1537a5a68a68 /test/sql/test_compiler.py | |
parent | a29245e247698160172e42e2154180997b81b8ba (diff) | |
download | sqlalchemy-1ac57f0b52e3e89097129931d46ebbbb39ee7927.tar.gz |
- [bug] Repaired common table expression
rendering to function correctly when the
SELECT statement contains UNION or other
compound expressions, courtesy btbuilder.
[ticket:2490]
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r-- | test/sql/test_compiler.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index dfdf8bd87..61dcf61ab 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -345,7 +345,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): eq_(s.positiontup, ['a', 'b', 'c']) def test_nested_label_targeting(self): - """test nested anonymous label generation. + """test nested anonymous label generation. """ s1 = table1.select() @@ -1203,7 +1203,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "SELECT mytable.myid, mytable.name, mytable.description " "FROM mytable WHERE mytable.myid = %(myid_1)s FOR SHARE", dialect=postgresql.dialect()) - + self.assert_compile( table1.select(table1.c.myid==7, for_update="read_nowait"), "SELECT mytable.myid, mytable.name, mytable.description " @@ -2446,6 +2446,46 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): dialect=mssql.dialect() ) + def test_cte_union(self): + orders = table('orders', + column('region'), + column('amount'), + ) + + regional_sales = select([ + orders.c.region, + orders.c.amount + ]).cte("regional_sales") + + s = select([regional_sales.c.region]).\ + where( + regional_sales.c.amount > 500 + ) + + self.assert_compile(s, + "WITH regional_sales AS " + "(SELECT orders.region AS region, " + "orders.amount AS amount FROM orders) " + "SELECT regional_sales.region " + "FROM regional_sales WHERE " + "regional_sales.amount > :amount_1") + + s = s.union_all( + select([regional_sales.c.region]).\ + where( + regional_sales.c.amount < 300 + ) + ) + self.assert_compile(s, + "WITH regional_sales AS " + "(SELECT orders.region AS region, " + "orders.amount AS amount FROM orders) " + "SELECT regional_sales.region FROM regional_sales " + "WHERE regional_sales.amount > :amount_1 " + "UNION ALL SELECT regional_sales.region " + "FROM regional_sales WHERE " + "regional_sales.amount < :amount_2") + def test_date_between(self): import datetime table = Table('dt', metadata, |