Skip to content

Instantly share code, notes, and snippets.

@jmeller
jmeller / upsert_from_pandas_to_postgres.py
Created March 4, 2020 14:03 — forked from Nikolay-Lysenko/upsert_from_pandas_to_postgres.py
Upsert (a hybrid of insert and update) from pandas.DataFrame to PostgreSQL database
from time import sleep
from io import StringIO
import psycopg2
def upsert_df_into_postgres(df, target_table, primary_keys, conn_string,
n_trials=5, quoting=None, null_repr=None):
"""
Uploads data from `df` to `target_table`