Last active
April 6, 2022 06:37
-
-
Save RICH0423/732d6ca30f67e3f1f6496e1d3ce63d18 to your computer and use it in GitHub Desktop.
Testing PostgreSQL connection with 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 psycopg2 | |
#establishing the connection | |
conn = psycopg2.connect( | |
database="postgres", user='postgres', password='12345678', host='127.0.0.1', port= '5432' | |
) | |
#Creating a cursor object using the cursor() method | |
cursor = conn.cursor() | |
#Executing an MYSQL function using the execute() method | |
cursor.execute("select version()") | |
# Fetch a single row using fetchone() method. | |
data = cursor.fetchone() | |
print("Connection established to: ",data) | |
#Closing the connection | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip install psycopg2