【问题标题】:Selecting data from schema based table in Postgresql using psycopg2使用 psycopg2 从 Postgresql 中基于模式的表中选择数据
【发布时间】:2019-09-14 06:49:01
【问题描述】:

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

显示错误relation dl.products 不存在

谁能告诉我如何做到这一点的例子?

【问题讨论】:

    标签: python python-3.x postgresql python-2.7 psycopg2


    【解决方案1】:

    请尝试以下代码,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-31
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 2010-10-18
      • 1970-01-01
      相关资源
      最近更新 更多