to_sql + sqlalchemy +从+ postgresql引擎复制? [英] to_sql + sqlalchemy + copy from + postgresql engine?

查看:98
本文介绍了to_sql + sqlalchemy +从+ postgresql引擎复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试熊猫 DataFrame to_sql 方法。

I'm testing the to_sql method of pandas DataFrame.

to_sql 使用的是 INSERT SQL方法,这比 COPY FROM要慢 SQL方法。

to_sql is using INSERT SQL method and this is slower than COPY FROM SQL method.

我可以选择 COPY FROM SQL方法使用 to_sql ,使用SQLAlchemy和Postgresql(psycopg2)引擎?

Can I select the COPY FROM SQL method to be used by to_sql, using SQLAlchemy and Postgresql (psycopg2) engine?

推荐答案

您是正确的 to_sql 通过sqlalchemy使用 INSERT INTO (发生这种情况的代码是此处),因此您不能使用使用 to_sql 复制。

You are correct to_sql is using INSERT INTO via sqlalchemy (code where this happens is here), and so naturally you cannot use COPY FROM using to_sql.

但是如果您需要这样,您当然可以使用它自己实现 to_sql 的实现。而且,如果您认为这样做的性能和功能与当前实现的更好,您可以随时向pandas发送文稿( https://github.com/pydata/pandas/blob/master/CONTRIBUTING.md )。

But if you need this, you can of course make an own implementation of to_sql using that. And if you think this has much better performance and the same functionality as the current implementation, you can always send a contribution to pandas (https://github.com/pydata/pandas/blob/master/CONTRIBUTING.md).

但是,据我了解,如果要以从文件复制表中执行SQL语句,则始终可以使用 execute 命令。

But, as far as I understand, if you want to execute an SQL statement as "COPY table FROM file", you can always just use the execute command of the postgres engine.

这篇关于to_sql + sqlalchemy +从+ postgresql引擎复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆