summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-11-23 20:13:20 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-11-23 20:13:20 -0500
commit584cabbf7e79948e38b29df5af63c3c712566f31 (patch)
treec4e8451d7f4b794826d20ecf18b8252099fadf25 /test/dialect/postgresql/test_compiler.py
parentb4e40b35627f1c26b84234d16a36ce2850a798b9 (diff)
downloadsqlalchemy-584cabbf7e79948e38b29df5af63c3c712566f31.tar.gz
Support Column objects in the SET clause for upsert
Established support for :class:`_schema.Column` objects as well as ORM instrumented attributes as keys in the ``set_`` dictionary passed to the :meth:`_postgresql.Insert.on_conflict_do_update` and :meth:`_sqlite.Insert.on_conflict_do_update` methods, which match to the :class:`_schema.Column` objects in the ``.c`` collection of the target :class:`_schema.Table`. Previously, only string column names were expected; a column expression would be assumed to be an out-of-table expression that would render fully along with a warning. Fixes: #5722 Change-Id: Ice73b501d721c28d978a0277a83cedc6aff756a9
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index a031c3df9..9651f7bd9 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -1864,6 +1864,31 @@ class InsertOnConflictTest(fixtures.TestBase, AssertsCompiledSQL):
},
)
+ def test_do_update_set_clause_column_keys(self):
+ i = insert(self.table_with_metadata).values(myid=1, name="foo")
+ i = i.on_conflict_do_update(
+ index_elements=["myid"],
+ set_=OrderedDict(
+ [
+ (self.table_with_metadata.c.name, "I'm a name"),
+ (self.table_with_metadata.c.description, None),
+ ]
+ ),
+ )
+ self.assert_compile(
+ i,
+ "INSERT INTO mytable (myid, name) VALUES "
+ "(%(myid)s, %(name)s) ON CONFLICT (myid) "
+ "DO UPDATE SET name = %(param_1)s, "
+ "description = %(param_2)s",
+ {
+ "myid": 1,
+ "name": "foo",
+ "param_1": "I'm a name",
+ "param_2": None,
+ },
+ )
+
def test_do_update_set_clause_literal(self):
i = insert(self.table_with_metadata).values(myid=1, name="foo")
i = i.on_conflict_do_update(