Skip to content

Instantly share code, notes, and snippets.

@dimastatz
Created July 8, 2020 08:01
Show Gist options
  • Save dimastatz/89cd4f4cf0e5a40be8e01ac863300be3 to your computer and use it in GitHub Desktop.
Save dimastatz/89cd4f4cf0e5a40be8e01ac863300be3 to your computer and use it in GitHub Desktop.
def create_db_client(host, user, password, db):
import psycopg2
return psycopg2.connect(host=host, user=user, password=password, dbname=db)
def insert_to_db(conn, table, values: list):
v = ['({}),'.format(y for y in x) for x in values]
sql = 'insert into {} values {}'.format(table, v)
cur = conn.cursor()
cur.execute(sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment