I am trying to insert large number of rows into postgres using cursor.mogrify using this psycopg2: insert multiple rows with one query
data is a list of tuples where each tuple is a row that needs to be inserted.
cursor = conn.cursor()
args_str = ','.join(cursor.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in data)
cursor.execute(
"insert into table1 (n, p, r, c, date, p1, a, id) values " + args_str)`
but getting error :
TypeError: sequence item 0: expected str instance, bytes found
at line:
args_str = ','.join(cursor.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in data)
If I try to change to b''.join(cursor.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in data) , then execute query gives error for inserting byte....
Am I doing something wrong ?