Created
July 14, 2022 19:31
-
-
Save SebastianCB-dev/0e148549e4cc647f7e54ca9366996fbe to your computer and use it in GitHub Desktop.
This is a script to connect PostgreSQL with Python3
This file contains 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 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