You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
Version 1
Next »
Introduction
Sometimes connecting to the database directly using Python (or other programming language) is the best way forward. Some sample code is available below
import psycopg2
from psycopg2 import extras
# database credentials
database_host_url = 'abcd.amazon.com'
database_name = 'abcd1234'
database_username = 'polo5678'
database_pwd = 'password'
# Login to PostgreSQL database
canopy_postgresql_conn = psycopg2.connect(dbname=database_name, user=database_username, host=database_host_url, password=database_pwd)
canopy_postgresql_conn.autocommit = True
with canopy_postgresql_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as temp_cursor:
temp_cursor.execute("select * from consolidated_holdings limit 5;")
results = temp_cursor.fetchall()
for row in results:
print (row)