I was trying to update a table row from the line in PostgreSQL using Python.
The code used was
cursor.execute ("update im_entry.pr_table set selected_entry = im_entry.usr_table.", Entryn, "im_entry.usr_table where from im_entry.pr_table .image_1d = ", IDN," ") ... where entn and idn two string variables (entry 1, entry 2 .. ID1, ID2 etc etc) I am getting an error
Writing Error: The function takes atleast 3 arguments (5) )
My table is
image_1d | Entry 1 | Entry 2 | Entry 3 | Entry 4 | Entry ---------- + -------- + -------- + -------- + -------- + - - ----- How can I solve it? Try
:
cursor.execute ('' ' .im updated im_entry.pr_table set selected_entry = im_entry.usr_table {0} im_entry.pr_table.image_1d = '' '.format (entryn), [IDN]) from im_entry.usr_table Normally, you have a parametrized SQL query for cursor.execute (SQL, args) , where sql / call> is a query, and args The replacement parameters for the list or values are being replaced for the placeholder. For Postgresql, the common database driver, pyscopg, uses the question mark for parameter placeholder.
In this way, usually, you want to use some kind of
sql = '' 'UPDATE im_entry.pr_table SET selected_entry =? Im_entry.usr_table with WHERE im_entry.pr_table.image_1d =? '' ' But in your case, you are not trying to set selected_entry in a specific value, but rather for a column name. Is that right? In that case, you can not unfortunately use the parameter placeholder instead, instead, you have to use string formatting, which I have suggested above.
Comments
Post a Comment