dictionary = testEns(idSession)
columns = dictionary.keys()
for i in dictionary.values():
sql2='''insert into PERSONS(person_id , person_name) VALUES{};'''.format(i)
cursor.execute(sql2)
The function testEns(idSession) contains the result of an api call that returns an xml response that has been transformed into a dictionary.
i’m trying to insert the response into a table that have been created in a postgres database but here is the error i’m getting. Any idea why? and what am i missing?
psycopg2.errors.SyntaxError: syntax error at or near "{"
LINE1: ...nsert into PERSONS(person_id, person_name) VALUES{'category...
After I changed VALUES{id, name} to VALUES(id, name)
I have this error
psycopg2.errors.UndefinedColumn: column "id" does not exist
LINE 1: ...sert into PERSONS(person_id , person_name) VALUES(id, name)
eve though my table PERSONS is created in pgadmin with the columns id and name
2
Answers
Your line
Should be fixed
Your SQL statement looks off, I think you want something like:
Assuming the property names in
i
here.