im trying to escape characters to create a transaction block in python and commit it all at once with no success...
for example:
def transaction_block(sql):
global sql_transaction
sql_transaction.append(sql)
if len(sql_transaction) > 1000:
db.execute('BEGIN TRANSACTION')
for s in sql_transaction:
try:
db.execute(s)
except Exception as e:
print(e)
db.commit()
sql_transaction = []
def sql_insert_comment(parentid,comment):
try:
sql = "INSERT INTO p_reply (parent_id, comment) VALUES ('{}','{}');".format(parentid, comment)
transaction_block(sql)
except Exception as e:
print('error s02',str(e))
how should i adapt this to use the %s so i can escape it all? or there is a better way to accomplish this?
###UPDATE 1###
found a possible answer using execute_values() credits to: https://billyfung.com/writing/2017/06/improving-multiple-inserts-with-psycopg2/
700% increase performance
IF you know a better way yet, please let me know ;)