I am trying to format a insert query string for multiple rows but also with ON CONFLICT. I got all mixed up with formatting arguments.
ses_crud_sql = """INSERT INTO session_crud(orgid, appid, sessionid, userid, customlabel, uploadedon)
VALUES (%s, %s, %s, %s, %s, %s)
ON CONFLICT (orgid, appid)
DO UPDATE SET customlabel = array_append(customlabel, '%(label_name)s') WHERE sessionid=sessionid
"""
ses_crud_rows = [(org_id, app_id, sessionid, userid, str({label_name}), datetime.strftime(current_time, '%Y-%m-%d %H:%M:%S'))
for sessionid in session_ids]
cursor.executemany(ses_crud_sql, ses_crud_rows)
I need to insert multiple rows for every session in session_ids list.
So I also want to add %(label_name)s but this gives me
psycopg2.ProgrammingError: argument formats can't be mixed