From 584cabbf7e79948e38b29df5af63c3c712566f31 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 23 Nov 2020 20:13:20 -0500 Subject: 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 --- test/dialect/postgresql/test_compiler.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/dialect/postgresql/test_compiler.py') 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( -- cgit v1.2.1