Skip to content

Instantly share code, notes, and snippets.

View ypraw's full-sized avatar
💭
Type the code ...

Yunindyo Prabowo ypraw

💭
Type the code ...
View GitHub Profile
@ypraw
ypraw / bulkupsert.py
Created October 28, 2021 04:54 — forked from luke/bulkupsert.py
I needed to upsert (insert or update) bajillions of records into postgresql. After trying various libs including upsert (which was slow as hell) I ended up doing a bit of research and trying 3 different methods. This one won. While I'm manually building the sql string no user data is passed in. Its loaded via the copy from statement as CSV. Call…
import logging
import cStringIO
import csv
DEBUG = False
def data2csv(data):
si = cStringIO.StringIO()
cw = csv.writer(si, delimiter='\t',lineterminator="\n")
for row in data: