How do I write a pandas dataframe to Vertica?

后端 未结 1 601
無奈伤痛
無奈伤痛 2021-01-21 18:39

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 da

相关标签:
1条回答
  • 2021-01-21 19:09

    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.

    0 讨论(0)
提交回复
热议问题