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

2024-09-30 00:33:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python的新手,我想使用pythonspsycopg2api从postgreSQL数据库中选择一些数据。在

我选择的表在模式dl中(dl.产品),所以当我写代码时

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

它显示了误差关系dl.产品不存在。在

有人能给我举个例子吗?在


Tags: 数据代码数据库host产品postgresqlconnect模式
1条回答
网友
1楼 · 发布于 2024-09-30 00:33:44

请尝试下面的代码

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

相关问题 更多 >

    热门问题