【问题标题】:psycopg2.ProgrammingError: column does not existpsycopg2.ProgrammingError:列不存在
【发布时间】:2016-06-14 07:36:05
【问题描述】:

当我尝试通过 python.roll_no 对数据库进行查询时,我收到以下错误,这是表中的关键。

File "class_room.py", line 30, in get
cursor.execute("select first_name from class_room where keyword=%s",     (roll_no))
psycopg2.ProgrammingError: column "keyword" does not exist
LINE 1: select first_name from class_room where keyword='3'


                                           ^
12:21 class_room=# \d+ class_room
                               Table "public.class_room"
  Column   |  Type   |         Modifiers         | Storage  | Stats target |   Description
------------+---------+---------------------------+----------+--------------+-      ------------
roll_no    | integer | not null                  | plain    |              |
first_name | text    | not null default ''::text | extended |              |
last_name  | text    | not null default ''::text | extended |              |
marks      | integer |                           | plain    |              |
Indexes:
   "class_room_pkey" PRIMARY KEY, btree (roll_no)
Has OIDs: no



user:~/pathclass_room $ cat schema.sql
create table class_room (
roll_no int primary key,
first_name text not null default '',
last_name text not null default '',
marks int
);

【问题讨论】:

  • 什么是keyword?你没有这样的专栏。
  • 就像上面写的@sagi。有时我在使用' ' 而不是" " 时会遇到类似的错误,反之亦然。但是这里好像你没有专栏。

标签: sql database postgresql python-3.x psycopg2


【解决方案1】:

改为:

cursor.execute("select first_name from class_room where roll_no = %s", (roll_no,))

roll_no 后不要省略逗号。它将带括号的表达式变成一个元组。

【讨论】:

  • 谢谢,有帮助。
猜你喜欢
  • 2020-02-09
  • 2018-05-23
  • 1970-01-01
  • 1970-01-01
  • 2018-12-17
  • 1970-01-01
  • 2017-06-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多