summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-02-27 12:48:54 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-02-27 12:49:31 -0500
commit0c31059a1d6303d2d16b59eb6a5c2c751acdf14a (patch)
tree2c2f51d9b72714da076521932f57735dca02caa5 /test/sql
parentdc615763d39916e9c037c7c376db1817cdf02764 (diff)
downloadsqlalchemy-0c31059a1d6303d2d16b59eb6a5c2c751acdf14a.tar.gz
support stringify for plain CTE
Altered the compilation for the :class:`.CTE` construct so that a string is returned representing the inner SELECT statement if the :class:`.CTE` is stringified directly, outside of the context of an enclosing SELECT; This is the same behavior of :meth:`_FromClause.alias` and :meth:`_SelectStatement.subquery`. Previously, a blank string would be returned as the CTE is normally placed above a SELECT after that SELECT has been generated, which is generally misleading when debugging. Change-Id: Id3007c28e4a7a56d867e850bb890752946bd8f6f References: #5988
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_compiler.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index 140de8622..acf16ca1c 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -4309,6 +4309,17 @@ class StringifySpecialTest(fixtures.TestBase):
"SELECT anon_1.myid FROM anon_1",
)
+ @testing.combinations(("cte",), ("alias",), ("subquery",))
+ def test_grouped_selectables_print_alone(self, modifier):
+ stmt = select(table1).where(table1.c.myid == 10)
+
+ grouped = getattr(stmt, modifier)()
+ eq_ignore_whitespace(
+ str(grouped),
+ "SELECT mytable.myid, mytable.name, "
+ "mytable.description FROM mytable WHERE mytable.myid = :myid_1",
+ )
+
def test_next_sequence_value(self):
# using descriptive text that is intentionally not compatible
# with any particular backend, since all backends have different