Last active
September 8, 2018 13:00
-
-
Save theholy7/bd3916f370747d781410772c8ae783e1 to your computer and use it in GitHub Desktop.
psycopg2, pandas and 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 os | |
import pandas.io.sql as sqlio | |
import psycopg2 | |
from dotenv import load_dotenv, find_dotenv | |
load_dotenv(find_dotenv()) | |
SQL_USER = os.environ.get('SQL_USER') | |
SQL_PASS = os.environ.get('SQL_PASS') | |
SQL_HOST = os.environ.get('SQL_HOST') | |
SQL_PORT = os.environ.get('SQL_PORT') | |
SQL_DB = os.environ.get('SQL_DB') | |
conn = psycopg2.connect( | |
dbname=SQL_DB, | |
user=SQL_USER, | |
password=SQL_PASS, | |
port=SQL_PORT, | |
host=SQL_HOST | |
) | |
SQL_QUERY = "SELECT * FROM test_table WHERE id = ANY(%s)" | |
test_ids = [1, 2, 3] | |
result_df = sqlio.read_sql_query(SQL_QUERY, params=(test_ids,), conn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment