[Sqlalchemy-tickets] Issue #3828: Postgres multi-value insert fails with enum-type columns and on_c
Brought to you by:
zzzeek
From: Basti <iss...@bi...> - 2016-10-17 11:57:51
|
New issue 3828: Postgres multi-value insert fails with enum-type columns and on_conflict statement https://bitbucket.org/zzzeek/sqlalchemy/issues/3828/postgres-multi-value-insert-fails-with Basti: When creating a (postgres specific) insert statement for a table with a enum typed column, the compilation of the statement fails if the enum-column is used in the `on_conflict` where-condition. Minimal Example: ``` #!python import sqlalchemy as _sa from sqlalchemy.dialects import postgresql as t from st.db.schema import PrimaryKey as PrimaryKey test_table = _sa.Table(u'test_table', _sa.MetaData(), _sa.Column('id', t.INTEGER, nullable=False, autoincrement=False), _sa.Column('state', t.ENUM(u'1st', u'2nd', u'3rd'), nullable=False), ) PrimaryKey( test_table.c.id, name=u'test_table_pkey', ) PG_INSERT = t.insert values = [dict(id=100, state=u'1st'), dict(id=200, state=u'1st')] stmt = PG_INSERT(test_table, values) stmt = stmt.on_conflict_do_update( index_elements=['id'], set_=dict(id=1000), where=(stmt.excluded.state == '2nd') ) str(stmt.compile(dialect=t.dialect())) # Fails with 'sqlalchemy.exc.CompileError: Bind parameter '%(4378430864 state)s' # conflicts with unique bind parameter of the same name' ``` If instead of a list of values, a single dict is used in the `insert()` call everything is compiled correctly. Also multi-values work if the where-condition is replaced with any other (non-enum) column. |