summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-07-29 14:49:22 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-07-29 14:52:40 -0400
commit2ce8a04e726daecbf060684dcee7559634506700 (patch)
treea226c22b20772a9f1cdfa4b662e9f9ea742ab9fd /test/sql
parentaef6e625ba5799bf5935ba3acbb62a37c9e577ca (diff)
downloadsqlalchemy-2ce8a04e726daecbf060684dcee7559634506700.tar.gz
Invoke column_expression() for subsequent SELECTs in CompoundSelect
Fixed bug where :meth:`.TypeEngine.column_expression` method would not be applied to subsequent SELECT statements inside of a UNION or other :class:`.CompoundSelect`, even though the SELECT statements are rendered at the topmost level of the statement. New logic now differentiates between rendering the column expression, which is needed for all SELECTs in the list, vs. gathering the returned data type for the result row, which is needed only for the first SELECT. Fixes: #4787 Change-Id: Iceb63e430e76d2365649aa25ead09c4e2a062e10
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_type_expressions.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/sql/test_type_expressions.py b/test/sql/test_type_expressions.py
index f913ab638..1f4649ffc 100644
--- a/test/sql/test_type_expressions.py
+++ b/test/sql/test_type_expressions.py
@@ -7,6 +7,7 @@ from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import testing
from sqlalchemy import TypeDecorator
+from sqlalchemy import union
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
@@ -272,6 +273,35 @@ class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL):
"test_table.y = outside_bind(inside_bind(:y_1))",
)
+ def test_compound_select(self):
+ table = self._fixture()
+
+ s1 = select([table]).where(table.c.y == "hi")
+ s2 = select([table]).where(table.c.y == "there")
+
+ self.assert_compile(
+ union(s1, s2),
+ "SELECT test_table.x, lower(test_table.y) AS y "
+ "FROM test_table WHERE test_table.y = lower(:y_1) "
+ "UNION SELECT test_table.x, lower(test_table.y) AS y "
+ "FROM test_table WHERE test_table.y = lower(:y_2)",
+ )
+
+ def test_select_of_compound_select(self):
+ table = self._fixture()
+
+ s1 = select([table]).where(table.c.y == "hi")
+ s2 = select([table]).where(table.c.y == "there")
+
+ self.assert_compile(
+ union(s1, s2).alias().select(),
+ "SELECT anon_1.x, lower(anon_1.y) AS y FROM "
+ "(SELECT test_table.x AS x, test_table.y AS y "
+ "FROM test_table WHERE test_table.y = lower(:y_1) "
+ "UNION SELECT test_table.x AS x, test_table.y AS y "
+ "FROM test_table WHERE test_table.y = lower(:y_2)) AS anon_1",
+ )
+
class DerivedTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = "default"