Loading CSV data to a PostgreSQL table

那年仲夏 提交于 2019-12-11 10:36:38

问题


What is the best way to load CSV data to a table in a PostgreSQL database (in Java)?

Context: I am working on extract, transform, load (ETL) processing - extracted the flat file and generated (csv's of a similar table). I want to load CSV files to a PostgreSQL table in Java.


回答1:


In PostgreSQL the usual way of copying data from a CSV file is the COPY statement (more information is in the the PostgreSQL documentation). To use this statement you must have have the file in a location readable by the server.

If the data cannot be put to the server readable location beforehand, you can use a psql \copy (more information) or INSERT statement.




回答2:


The fastest way of loading a CSV file into a PostgreSQL database is using the COPY command.

From the Java side you can use the method copyIn of CopyManager class from the PostgreSQL JDBC driver.



来源:https://stackoverflow.com/questions/28813025/loading-csv-data-to-a-postgresql-table

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