Skip to content

Instantly share code, notes, and snippets.

@buckbaskin
Created November 1, 2016 23:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buckbaskin/498c54d8ac13f687f7bdc5b14eb50df2 to your computer and use it in GitHub Desktop.
Save buckbaskin/498c54d8ac13f687f7bdc5b14eb50df2 to your computer and use it in GitHub Desktop.
A simple example of using Postgres in Python
import psycopg2
# make a connection
try:
conn = psycopg2.connect(database='postgres', user='postgres', password='economicalchinchillacorndog', host='localhost')
cur = conn.cursor()
except:
print('Database Connection Failed')
raise
# run a SQL query
cur.execute('SELECT * FROM orders')
# iterate through the results
for item in cur.fetchall():
print(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment