0

I am getting the below error when i am trying to make a query to the database via python.roll_no is the key as per the table.

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
);
2
  • 1
    What is keyword ? You don't have such column. Commented Jun 14, 2016 at 7:47
  • Like @sagi wrote above. Sometimes I have similar error when I use ' ' instead " " and vice versa in string of sql query. But here it seems You do not have the column. Commented Jun 14, 2016 at 12:25

1 Answer 1

1

Change to:

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

Do not omit the comma after roll_no. It turns the parenthesised expression into a tuple.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks , That helped.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.