每天从MS SQL到PostgreSQL传输相当大量的数据(2mil +行)的最有效方法是什么?
现在我:
代码示例:
for date_range中的query_date: query =' SELECT * FROM {} WHERE row_date =%s;' df = pd.read_sql_query(query.format(table_name),engine,params = {query_date})
def process_file(conn, table_name, file_object):
fake_conn = pg_engine.raw_connection()
fake_cur = fake_conn.cursor()
fake_cur.copy_expert(sql='''COPY %s FROM STDIN WITH CSV HEADER''' % table_name, file=file_object)
fake_conn.commit()
fake_cur.close()
df.to_csv('../raw/temp_' + table_name + ext, index=False)
df = open('../raw/temp_' + table_name + ext)
process_file(conn=pg_engine, table_name=table_name, file_object=df)