将 CSV 数据加载到 PostgreSQL table

Loading CSV data to a PostgreSQL table

加载 CSV data to a table in a PostgreSQL 数据库(在 Java 中)的最佳方法是什么?

上下文:我正在进行 extract, transform, load (ETL) 处理 - 提取平面文件并生成(类似 table 的 csv)。我想将 CSV 文件加载到 Java.

中的 PostgreSQL table

在 PostgreSQL 中,从 CSV 文件复制数据的常用方法是 COPY 语句(更多信息在 the PostgreSQL documentation 中)。要使用此语句,您必须将文件放在服务器可读的位置。

如果无法事先将数据放到服务器可读的位置,可以使用psql \copymore information)或INSERT语句。

将 CSV 文件加载到 PostgreSQL 数据库的最快方法是使用 COPY command

从 Java 方面,您可以使用方法 copyIn of CopyManager class from the PostgreSQL JDBC 驱动程序。