Refer to this code and video tutorial –
import psycopg2
connection = psycopg2.connect(user = "postgres",
password = "pwd",
host = "127.0.0.1",
port = "5432",
database = "northwind")
SELECT usename
FROM pg_user;
cursor = connection.cursor()
cursor.execute("Select * From products")
cursor.fetchall()
Buy Full Course – https://www.udemy.com/course/postgresql-tutorial-for-db-administration-and-data-analysis/learn/