summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-07-12 16:53:37 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-07-13 11:49:34 -0400
commit889c011a0f7bce82cea1c9c2ac0c46cec4353d4d (patch)
treee64002939638ab49fd52d7a52ba1197f5a9558dd /test/sql
parentd80b709ea0a683b10ae46bb552204be59b5c73f8 (diff)
downloadsqlalchemy-889c011a0f7bce82cea1c9c2ac0c46cec4353d4d.tar.gz
Ensure DML provides named_with_column for CTE(Alias)
Fixed bug in new CTE feature for update/insert/delete whereby an anoymous (e.g. no name passed) :class:`.CTE` construct around the statement would fail. The Alias base class of CTE checks for the "named_with_column" attribute in order to detect if the underlying selectable has a name; UpdateBase now provides this as False. Change-Id: I4b0309db21379a4c0cb93085298c86da3cf840e4 Fixes: #3744
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_cte.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py
index aa674403e..35d455257 100644
--- a/test/sql/test_cte.py
+++ b/test/sql/test_cte.py
@@ -530,6 +530,38 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL):
"upsert.quantity FROM upsert))"
)
+ def test_anon_update_cte(self):
+ orders = table(
+ 'orders',
+ column('region')
+ )
+ stmt = orders.update().where(orders.c.region == 'x').\
+ values(region='y').\
+ returning(orders.c.region).cte()
+
+ self.assert_compile(
+ stmt.select(),
+ "WITH anon_1 AS (UPDATE orders SET region=:region "
+ "WHERE orders.region = :region_1 RETURNING orders.region) "
+ "SELECT anon_1.region FROM anon_1"
+ )
+
+ def test_anon_insert_cte(self):
+ orders = table(
+ 'orders',
+ column('region')
+ )
+ stmt = orders.insert().\
+ values(region='y').\
+ returning(orders.c.region).cte()
+
+ self.assert_compile(
+ stmt.select(),
+ "WITH anon_1 AS (INSERT INTO orders (region) "
+ "VALUES (:region) RETURNING orders.region) "
+ "SELECT anon_1.region FROM anon_1"
+ )
+
def test_pg_example_one(self):
products = table('products', column('id'), column('date'))
products_log = table('products_log', column('id'), column('date'))