mfenniak / pg8000

A Pure-Python PostgreSQL Driver
http://pythonhosted.org/pg8000/
Other
222 stars 55 forks source link

Cannot execute DELETE query #133

Closed UshakovVasilii closed 7 years ago

UshakovVasilii commented 7 years ago

Code:

import pg8000

connection = pg8000.connect(...)
cursor = connection.cursor()

cursor.execute("DELETE FROM message WHERE phrase=%s", ('test'))

Error:

pg8000.core.ProgrammingError: ('ERROR', 'ERROR', '42P18', 'could not determine data type of parameter $2', 'postgres.c', '1344', 'exec_parse_message', '', '')
cursor.execute("DELETE FROM message WHERE phrase=%s::text", ('test'))
pg8000.core.ProgrammingError: ('ERROR', 'ERROR', '42P18', 'could not determine data type of parameter $2', 'postgres.c', '1344', 'exec_parse_message', '', '')
cursor.execute("DELETE FROM message WHERE phrase=:1", ('test'))
pg8000.core.ProgrammingError: ('ERROR', 'ERROR', '42601', 'syntax error at or near ":"', '34', 'scan.l', '1086', 'scanner_yyerror', '', '')
cursor.execute("DELETE FROM message WHERE phrase=?", ('test'))
pg8000.core.ProgrammingError: ('ERROR', 'ERROR', '42883', 'operator does not exist: text =?', 'No operator matches the given name and argument type(s). You might need to add explicit type casts.', '33', 'parse_oper.c', '726', 'op_error', '', '')

table:

  Column  |          Type          | Modifiers 
----------+------------------------+-----------
 phrase   | text                   | not null
 category | character varying(255) | not null
Indexes:
    "message_pkey" PRIMARY KEY, btree (phrase)
CREATE TABLE message (
    phrase text NOT NULL,
    category character varying(255) NOT NULL
);
ALTER TABLE message
    ADD CONSTRAINT message_pkey PRIMARY KEY (phrase);
UshakovVasilii commented 7 years ago

Oh, one element tuple...

cursor.execute("DELETE FROM message WHERE phrase=%s", ('test'))

=>

cursor.execute("DELETE FROM message WHERE phrase=%s", ('test', ))