Skip to content

Instantly share code, notes, and snippets.

View hans-fischer's full-sized avatar
🎩
be my guest

Hans Fischer hans-fischer

🎩
be my guest
View GitHub Profile
@aisayko
aisayko / bulk_upsert.py
Last active May 8, 2022 23:53
Postgresql bulk upsert in Python (Django)
def bulk_upsert(model, fields, values, by):
"""
Return the tuple of (inserted, updated) ids
"""
result = (None, None)
if values:
stmt = """
WITH data_set AS (
INSERT INTO %s (%s)