[Sqlalchemy-tickets] Issue #3639: insert().select_from() ignores custom dialect-specific keywords (
Brought to you by:
zzzeek
|
From: Drino <iss...@bi...> - 2016-01-27 09:16:07
|
New issue 3639: insert().select_from() ignores custom dialect-specific keywords https://bitbucket.org/zzzeek/sqlalchemy/issues/3639/insert-select_from-ignores-custom-dialect Drino: I use sqlalchemy 1.0.11 with postgresql database. I want to merge two tables and use "ON CONFLICT IGNORE" postgresql-specific keyword to do this. I want to do it the right way and probably want to use "ON CONFLICT" construct somewhere else in my code. So I write the following: ``` #!python @compiles(Insert) def postgresql_on_conflict(insert, compiler, **kw): s = compiler.visit_insert(insert, **kw) if insert.kwargs.get('postgresql_on_conflict') is not None: return s + " ON CONFLICT " + insert.kwargs['postgresql_on_conflict'] return s Insert.argument_for('postgresql', 'on_conflict', None) print tableA.insert(postgresql_on_conflict='IGNORE').from_select(tableB.c, tableB.select()).compile() ``` And it produces the following output: ``` #!sql INSERT INTO general."tablea" (field) SELECT field FROM general."tableb" ``` The postgresql_on_conflict keyword works fine by itself. |