Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SebastianCB-dev/0e148549e4cc647f7e54ca9366996fbe to your computer and use it in GitHub Desktop.
Save SebastianCB-dev/0e148549e4cc647f7e54ca9366996fbe to your computer and use it in GitHub Desktop.
This is a script to connect PostgreSQL with Python3
import psycopg2 as pg
conn = pg.connect(user="postgres",
password="root",
host="localhost",
port="5432",
database="python_postgres")
try:
with conn as cn:
with cn.cursor() as cursor:
sentence = ""
except(Exception) as e:
print("Error: unable to fetch data -", e)
finally:
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment