Pandas到PostGREs表收集执行详细信息

2024-10-01 09:40:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我成功地从pandas数据框将记录插入PostGREs表。 代码如下所示

try:
    engine = create_engine('postgresql://***CONNECTION***')
    connection = engine.raw_connection()
    dataframe1.to_sql('table1', con=engine, schema='public', index=False, if_exists='append')
except (Exception) as error :
    print ("Error while connecting to PostgreSQL", error)
finally:
    #closing database connection.
    if(connection):
        connection.close()
        print("PostgreSQL connection is closed")

我希望将执行统计数据写入日志文件。我要查找插入、拒绝的记录数、执行时间等

非常感谢您的任何帮助/建议


Tags: to数据代码pandasifpostgresqlcreate记录