How do I write a pandas dataframe to Vertica?

爷,独闯天下 提交于 2019-12-02 04:55:54

问题


I have some data set in a pandas data frame that I wish to write to Vertica. I've already created my table using the vertica_python library. What is the best way to write my data frame to Vertica?


回答1:


Often when connecting to Vertica, you can use Postgresql as a stand-in since certain parts of Vertica were originally based on Postgresql.

from sqlalchemy import create_engine
engine = create_engine('postgresql://user:pass@host:5433/MYDB')
df.to_sql('table_name', engine)

If this doesn't work you could try out the vertica-sqlalchemy package.

Also, depending on the SQL created (and if the ODBC driver converts INSERT to a COPY) this might be very slow. If you find that it is doing lots of individual inserts on the database, you'll probably want to switch to a COPY method where you create strings and COPY FROM STDIN to make it faster.



来源:https://stackoverflow.com/questions/29973328/how-do-i-write-a-pandas-dataframe-to-vertica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!