2

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?

1 Answer 1

3

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.