Reputation: 597
I'm a newbie in Python and would like to select some data from postgreSQL database using python psycopg2 API.
The table I'm selecting is inside a schema dl(dl.products),so when I write the code
Conn= psycopg2.connect(host="localhost",database="postgres",user="postgres", password="postgres")
Cur=conn.cursor()
Cur.execute("select * from dl.products")
It's showing the error relation dl.products doesn't exists.
Can anyone show me an example on how to do this?
Upvotes: 2
Views: 4220
Reputation: 721
Please try the below code,
Query = """select * from dl."products";"""
cursor.execute(Query)
print("Selecting rows from test table using cursor.fetchall")
row = cursor.fetchone()
while row is not None:
print(row)
row = cursor.fetchone()
print("Print each row and it's columns values")
Upvotes: 3