no module psycopg2
# For quick install
pip install psycopg2-binary
# For production-ready install
pip install psycopg2
# But it will fail if build prerequesties are not met:
# https://www.psycopg.org/docs/install.html#build-prerequisites
no module psycopg2
# For quick install
pip install psycopg2-binary
# For production-ready install
pip install psycopg2
# But it will fail if build prerequesties are not met:
# https://www.psycopg.org/docs/install.html#build-prerequisites
psycopg2 select example
import psycopg2
try:
connection = psycopg2.connect(user="sysadmin",
password="pynative@#29",
host="127.0.0.1",
port="5432",
database="postgres_db")
cursor = connection.cursor()
postgreSQL_select_Query = "select * from mobile"
cursor.execute(postgreSQL_select_Query)
print("Selecting rows from mobile table using cursor.fetchall")
mobile_records = cursor.fetchall()
print("Print each row and it's columns values")
for row in mobile_records:
print("Id = ", row[0], )
print("Model = ", row[1])
print("Price = ", row[2], "\n")
except (Exception, psycopg2.Error) as error :
print ("Error while fetching data from PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us