Skip to content

Instantly share code, notes, and snippets.

@droustchev
droustchev / sqlalchemy_insert_ext.py
Last active August 6, 2022 23:34 — forked from kung-foo/gist:1730627
SQLAlchemy extension for "ON DUPLICATE KEY UPDATE"
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import Insert
@compiles(Insert)
def append_string(insert, compiler, **kw):
s = compiler.visit_insert(insert, **kw)
if 'append_string' in insert.kwargs:
return s + " " + insert.kwargs['append_string']
return s