问题
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