繁体   English   中英

使用psycopg2从Postgresql中基于模式的表中选择数据

[英]Selecting data from schema based table in Postgresql using psycopg2

我是Python的新手,并且想使用python psycopg2 API从postgreSQL数据库中选择一些数据。

我选择的表位于模式dl(dl.products)内,所以当我编写代码时

Conn=   psycopg2.connect(host="localhost",database="postgres",user="postgres", password="postgres")
  Cur=conn.cursor()
  Cur.execute("select * from dl.products")

它显示错误关系dl.products不存在

谁能给我示范如何做的例子?

请尝试以下代码,

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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