I'm trying to update my data from a pandas dataframe:
with engine.begin() as conn:
for d in range(0, len(df)):
query = """ UPDATE table AS p SET name='%s' WHERE p.id='%s'
""" % (df['name'][d], df['id'][d])
conn.execute(query)
The problem is one of the names is some like D'Artagnan, and it is having this error: sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) syntax
error at or near "D"
LINE 3: ... name='D'Artagnan', ...
[SQL: UPDATE table AS p SET name='D'Artagnan'
WHERE p.id='4342']
(Background on this error at: http://sqlalche.me/e/f405)
The problem is I really need this data in this way in my database. Does someone have any idea?