我已尽力而为,但仍然出现此错误:
2023-09-11 22:45:35,033 ERROR <class 'psycopg2.errors.UndefinedColumn'>: column u.id does not exist
LINE 1: ...id, u.balance FROM key k JOIN user u ON k.user_id=u.id WHERE...
^
Python代码:
# this all below return the same error
# sql = """SELECT k.user_id, k.custom_rates, u.id, u.balance FROM key k JOIN user u ON k.user_id=u.id WHERE k.key='test'"""
# sql = "SELECT k.user_id, k.custom_rates, u.id, u.balance FROM user u JOIN key k ON k.user_id=u.id WHERE k.key='test'"
# sql = "SELECT k.user_id, k.custom_rates, u.id, u.balance FROM key k INNER JOIN user u ON k.user_id=u.id WHERE k.key='test'"
sql = "SELECT k.user_id, k.custom_rates, u.id, u.balance FROM key k JOIN user u ON k.user_id=u.id WHERE k.key='test'"
cursor.execute(sql)
res = cursor.fetchone()
什么是错误?
key 和 user 是保留字。尝试:
FROM "key" k JOIN "user" u