Created
August 10, 2016 07:33
-
-
Save mydreambei-ai/f19a2755d76c38161e069dcbb002a231 to your computer and use it in GitHub Desktop.
sqlalchemy on conflict do something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.ext.compiler import compiles | |
from sqlalchemy.sql.expression import Insert | |
# @compiles(Insert) | |
# def prefix_inserts(insert, compiler, **kw): | |
# sql = compiler.visit_insert(insert, **kw) | |
# if "RETURNING" not in sql: | |
# return sql + ' ON CONFLICT DO NOTHING' | |
# else: | |
# return sql | |
# sql = re.sub(r'(RETURNING .*$)', 'ON CONFLICT DO NOTHING \\1', sql, 0, re.I) | |
# return sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment