summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-07-12 21:53:11 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-07-12 21:53:11 +0000
commit18dba87757097b87495aed0ca9fc345a040da1f1 (patch)
tree9343faefb05f72d8c08d5f69897a76b85d2b1bae /test/dialect/postgresql/test_compiler.py
parentb7791290ed5499542d2e6d7bdfac252f7648f5fc (diff)
parent204ff1f60cf911b00b7494942fc58bc715dddeed (diff)
downloadsqlalchemy-18dba87757097b87495aed0ca9fc345a040da1f1.tar.gz
Merge "implement independent CTEs"
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index 84901d178..77b4242f1 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -2594,7 +2594,7 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL):
self.assert_compile(
stmt,
"WITH i_upsert AS "
- "(INSERT INTO mytable (name) VALUES (%(name)s) "
+ "(INSERT INTO mytable (name) VALUES (%(param_1)s) "
"ON CONFLICT (name, description) "
"WHERE description != %(description_1)s "
"DO UPDATE SET name = excluded.name "
@@ -2603,6 +2603,30 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL):
"FROM i_upsert",
)
+ def test_combined_with_cte(self):
+ t = table("t", column("c1"), column("c2"))
+
+ delete_statement_cte = t.delete().where(t.c.c1 < 1).cte("deletions")
+
+ insert_stmt = insert(t).values([{"c1": 1, "c2": 2}])
+ update_stmt = insert_stmt.on_conflict_do_update(
+ index_elements=[t.c.c1],
+ set_={
+ col.name: col
+ for col in insert_stmt.excluded
+ if col.name in ("c1", "c2")
+ },
+ ).add_cte(delete_statement_cte)
+
+ self.assert_compile(
+ update_stmt,
+ "WITH deletions AS (DELETE FROM t WHERE t.c1 < %(c1_1)s) "
+ "INSERT INTO t (c1, c2) VALUES (%(c1_m0)s, %(c2_m0)s) "
+ "ON CONFLICT (c1) DO UPDATE SET c1 = excluded.c1, "
+ "c2 = excluded.c2",
+ checkparams={"c1_m0": 1, "c2_m0": 2, "c1_1": 1},
+ )
+
def test_quote_raw_string_col(self):
t = table("t", column("FancyName"), column("other name"))