Skip to content

Instantly share code, notes, and snippets.

@omsobliga
Created June 5, 2018 10:45
Show Gist options
  • Save omsobliga/8e16814f1e0f3a9610f294af6aebfe4f to your computer and use it in GitHub Desktop.
Save omsobliga/8e16814f1e0f3a9610f294af6aebfe4f to your computer and use it in GitHub Desktop.
# INSERT INTO table_tags (tag) VALUES ('tag_a'),('tab_b'),('tag_c') ON DUPLICATE KEY UPDATE tag=tag;
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
my_connection.execute(my_table.insert(append_string = 'ON DUPLICATE KEY UPDATE foo=foo'), my_values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment