将CSV数据加载到PostgreSQL表中 [英] Loading CSV data to a PostgreSQL table
问题描述
将 CSV 数据加载到 PostgreSQL 数据库(使用Java)?
What is the best way to load CSV data to a table in a PostgreSQL database (in Java)?
上下文:我正在进行提取,转换,加载(ETL)处理-提取了平面文件并生成(类似表格的csv)。我想将CSV文件加载到Java中的PostgreSQL表中。
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.
推荐答案
在PostgreSQL中,从CSV文件复制数据的常用方法是 COPY
语句(更多信息在 PostgreSQL文档)。要使用此语句,您必须将文件放在服务器可读的位置。
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.
如果无法事先将数据放入服务器可读位置,则可以使用 psql \copy
(更多信息)或 INSERT
语句。
If the data cannot be put to the server readable location beforehand, you can use a psql \copy
(more information) or INSERT
statement.
这篇关于将CSV数据加载到PostgreSQL表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!