Skip to content

Instantly share code, notes, and snippets.

@meanother
Created October 14, 2021 19:18
Show Gist options
  • Save meanother/583cdd7eaa3e6cc2cbb960bd3aed0bf5 to your computer and use it in GitHub Desktop.
Save meanother/583cdd7eaa3e6cc2cbb960bd3aed0bf5 to your computer and use it in GitHub Desktop.
def insert_on_conflict(table: str, array: List, sql: str) -> None:
item = array[0]
columns = ', '.join(item.keys())
dd = ["%s" for _ in range(len(item.keys()))]
placeholders = ", ".join(dd)
row = sql.format(table, columns, placeholders)
cursor.executemany(row, [tuple(item.values()) for item in array])
conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment