AttributeError: 'psycopg2.extensions.cursor' object has no attribute 'fast_executemany'
to_sql() is too slow. so trying to resolve the problem. but when I run the following code I am getting :-
AttributeError: 'psycopg2.extensions.cursor' object has no attribute 'fast_executemany'
@event.listens_for(conn, 'before_cursor_execute')
def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
if executemany:
cursor.fast_executemany = True
cursor.commit()
use insert with tuples it around 200 time faster than executemany
in psycopg
args_str = ','.join(cur.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in tup)
cur.execute("INSERT INTO table VALUES " + args_str)
its equivalent of
INSERT INTO table VALUES ('a', 'b', 'c'), ('a', 'b', 'c'), ('a', 'b', 'c'), ('a', 'b', 'c');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With