keyshen
2020-10-26 10:39
采纳率: 50%
浏览 77

关于python使用postgreSQL问题

1.本人新手,今日练习python连接postgre数据库中,发现以下问题

# coding = utf-8
import psycopg2

conn = psycopg2.connect(database="School", user="postgres", password="aaaaaa", host="127.0.0.1", port="5432",
                        )

print("Opened database successfully")

cur = conn.cursor()
cur.execute("SELECT 课程号, 课程名称, 教师号  from Course")
rows = cur.fetchall()
for row in rows:
    print("课程号 = ", row[0])
    print("课程名称 = ", row[1])
    print("教师号 = ", row[2])

print("Operation done successfully")
conn.close()

之后出现错误

Traceback (most recent call last):
  File "C:/Users/Administrator.DESKTOP-02S6LKD/PycharmProjects/pythonProject/HelloWorld.py", line 10, in <module>
    cur.execute("SELECT 课程号, 课程名称, 教师号  from Course")
psycopg2.errors.UndefinedTable: relation "course" does not exist
LINE 1: SELECT 课程号, 课程名称, 教师号  from Course
                                              ^

数据库如下:
图片说明

这个很头痛,后来新建一个库,设置列表名全是英文又可以读取,是不是不能识别中文?

1条回答 默认 最新

相关推荐 更多相似问题