.. changelog::
:version: 1.1.4
+ .. change::
+ :tags: bug, postgresql
+ :tickets: 3846, 3807
+
+ Fixed regression caused by the fix in :ticket:`3807` (version 1.1.0)
+ where we ensured that the tablename was qualified in the WHERE clause
+ of the DO UPDATE portion of PostgreSQL's ON CONFLICT, however you
+ *cannot* put the table name in the WHERE clause in the actual ON
+ CONFLICT itself. This was an incorrect assumption, so that portion
+ of the change in :ticket:`3807` is rolled back.
+
.. change::
:tags: bug, orm
:tickets: 3845
self.assert_compile(i,
'INSERT INTO mytable (name) VALUES '
"(%(name)s) ON CONFLICT (name) "
- "WHERE mytable.name > %(name_1)s "
+ "WHERE name > %(name_1)s "
'DO UPDATE SET name = excluded.name')
def test_do_update_index_elements_where_target_multivalues(self):
"INSERT INTO mytable (name) "
"VALUES (%(name_m0)s), (%(name_m1)s), (%(name_m2)s) "
"ON CONFLICT (name) "
- "WHERE mytable.name > %(name_1)s "
+ "WHERE name > %(name_1)s "
"DO UPDATE SET name = excluded.name",
checkparams={
'name_1': 'm', 'name_m0': 'foo',
self.assert_compile(i,
'INSERT INTO mytable (name) VALUES '
"(%(name)s) ON CONFLICT (name) "
- "WHERE mytable.name > %(name_1)s "
+ "WHERE name > %(name_1)s "
'DO UPDATE SET name = excluded.name')
def test_do_update_unnamed_exclude_constraint_target(self):
self.assert_compile(i,
'INSERT INTO mytable (name) VALUES '
"(%(name)s) ON CONFLICT (name, description) "
- "WHERE mytable.description != %(description_1)s "
+ "WHERE description != %(description_1)s "
'DO UPDATE SET name = excluded.name')
def test_do_update_add_whereclause(self):
self.assert_compile(i,
'INSERT INTO mytable (name) VALUES '
"(%(name)s) ON CONFLICT (name, description) "
- "WHERE mytable.description != %(description_1)s "
+ "WHERE description != %(description_1)s "
'DO UPDATE SET name = excluded.name '
"WHERE mytable.name != %(name_1)s "
"AND mytable.description != %(description_2)s")
self.assert_compile(i,
'INSERT INTO mytable (name) VALUES '
"(%(name)s) ON CONFLICT (name, description) "
- "WHERE mytable.description != %(description_1)s "
+ "WHERE description != %(description_1)s "
'DO UPDATE SET name = excluded.name '
"WHERE mytable.name != excluded.name")
Column('login_email', String(50)),
Column('lets_index_this', String(50))
)
+ cls.unique_partial_index = schema.Index(
+ 'idx_unique_partial_name',
+ users_xtra.c.name, users_xtra.c.lets_index_this,
+ unique=True,
+ postgresql_where=users_xtra.c.lets_index_this == 'unique_name')
+
cls.unique_constraint = schema.UniqueConstraint(
users_xtra.c.login_email, name='uq_login_email')
cls.bogus_index = schema.Index(
lets_index_this='bogus')
)
+ def test_on_conflict_do_update_exotic_targets_six(self):
+ users = self.tables.users_xtra
+
+ with testing.db.connect() as conn:
+ conn.execute(
+ insert(users),
+ dict(
+ id=1, name='name1',
+ login_email='mail1@gmail.com',
+ lets_index_this='unique_name'
+ )
+ )
+
+ i = insert(users)
+ i = i.on_conflict_do_update(
+ index_elements=self.unique_partial_index.columns,
+ index_where=self.unique_partial_index.dialect_options
+ ['postgresql']['where'],
+ set_=dict(
+ name=i.excluded.name,
+ login_email=i.excluded.login_email),
+ )
+
+ conn.execute(
+ i,
+ [
+ dict(name='name1', login_email='mail2@gmail.com',
+ lets_index_this='unique_name'),
+ ]
+ )
+
+ eq_(
+ conn.execute(users.select()).fetchall(),
+ [
+ (1, 'name1', 'mail2@gmail.com', 'unique_name'),
+ ]
+ )
+
def test_on_conflict_do_update_no_row_actually_affected(self):
users = self.tables.users_xtra