On googling, I found documents about PyGreSQL library that would help me connect Python to Postgres.
However, I cannot find the link to download the package anywhere. Even this document: http://www.pygresql.org/install.html
talks about downloading the Windows Installer etc, but doesn't tell from where.
I want the connection to work for Python 2.7
Step 1: pip install psycopg2
Step 2: User below code:-
import psycopg2
connection = psycopg2.connect(database="dbname", user="username", password="pass", host="hostname", port=5432)
cursor = connection.cursor()
cursor.execute("SELECT * from portal.portal_users;")
# Fetch all rows from database
record = cursor.fetchall()
print("Data from Database:- ", record)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With