Created
May 21, 2018 16:43
-
-
Save rdapaz/0b92c0c8856315ff3c5b86e2d5c7258d to your computer and use it in GitHub Desktop.
Using PostgreSQL from Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
conn = psycopg2.connect("dbname='timesheets' user=postgres") | |
if True: | |
cur = conn.cursor() | |
sql = """ | |
CREATE TABLE IF NOT EXISTS \"public\".\"ts\" ( | |
id serial primary key, | |
dt date, | |
project text, | |
consultant text, | |
days decimal | |
) | |
""" | |
cur.execute(sql) | |
sql = """ INSERT INTO \"public\".\"ts\" ( | |
dt, project, consultant, days | |
) VALUES | |
(%s, %s, %s, %s) | |
""" | |
cur.executemany(sql, data) | |
conn.commit() | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment