属性错误:“psycopg2.extensions.cursor”对象没有属性“fast_executemany”
to_sql() 太慢。所以试图解决这个问题。但是当我运行以下代码时,我得到:-
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()
最佳答案
在元组中使用 insert 比 psycopg
中的 executemany
快约 200 倍
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)
相当于
INSERT INTO table VALUES ('a', 'b', 'c'), ('a', 'b', 'c'), ('a', 'b', 'c'), ('a', 'b', 'c');
关于python - 属性错误: 'psycopg2.extensions.cursor' object has no attribute 'fast_executemany' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53932097/