简体   繁体   中英

Selecting data from schema based table in Postgresql using psycopg2

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?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM