Skip to content

Instantly share code, notes, and snippets.

View jackiep00's full-sized avatar

Jack Yin jackiep00

View GitHub Profile
@jackiep00
jackiep00 / postgresql_df_upsert.py
Last active January 11, 2024 13:22 — forked from gordthompson/postgresql_df_upsert.py
Build a PostgreSQL INSERT … ON CONFLICT statement and upsert a DataFrame
# version 1.2 - 2022-10-04
import pandas as pd
import sqlalchemy as sa
import string, random
def df_upsert(data_frame, table_name, engine, schema=None, match_columns=None):
"""
Perform an "upsert" on a PostgreSQL table from a DataFrame.