Python で Redshift に接続するとき用のメモ
import pandas as pd
import psycopg2
con_format = 'dbname={dbname} ...'
db_info = {
'host': ...,
...
}
query = """
CREATE TABLE ...
"""
with psycopg2.connect(con_format.format(**db_info)) as con:
with con.cursor() as cur:
cur.execute(query)
con.commit()
query = """
SELECT ...
"""
with psycopg2.connect(con_format.format(**db_info)) as con:
df = pd.read_sql(query, con)
コメント