Parameters ? not working with python postgres

Viewed 1088

I am using python with postgres and i am trying this simple query but its not working and i am not able to find why

con = psycopg2.connect(**config)


self.cursor.execute("INSERT INTO mytable (id, age, year) VALUES (nextval('my_id_seq'), ?, ?)", ('77', '44'))

I am getting this error

psycopg2.ProgrammingError: syntax error at or near "," LINE 1: ...year) VALUES (nextval('my_id_seq'), ?, ?)

EDIT

This is the error

INSERT INTO mytable (id, age, year) VALUES (nextval('my_id_seq'), %s, %s)
'6.65', '4955/1'

  File "off.py", line 80, in writeRows
    self.cursor.execute(query, values)
TypeError: not all arguments converted during string formatting

CODE:

data = [('age', '6.65'), ('year', '4974/1'), . . ]
cols = ",".join(data.keys())
qmarks = ','.join(['%s' for s in data.keys()])
query = "INSERT INTO mytable (id, %s) VALUES (nextval('my_id_seq'), %s)" % (cols,qmarks)
self.cursor.execute(query, values)
1 Answers
Related