Skip to content

Instantly share code, notes, and snippets.

View urkh's full-sized avatar
🚀
Working from home

Gustavo León Tramontin urkh

🚀
Working from home
View GitHub Profile
@urkh
urkh / bulk_upsert.py
Created April 17, 2019 19:07 — forked from aisayko/bulk_upsert.py
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)