简体   繁体   English

如何使用 pgAdmin 将 CSV 文件导入 PostgreSQL 表

[英]How to import a CSV file to a PostgreSQL table using pgAdmin

I am trying to import the following csv file (named dummy.csv):我正在尝试导入以下csv 文件(名为 dummy.csv):

"F1", "F2", "F3" “F1”、“F2”、“F3”

1,2,"a" 1,2,"一"

3,4, "b" 3,4,“乙”

3.4,2.4,"c" 3.4,2.4,"c"

to PostgreSQL using the pgAdmin GUI with the following command:使用pgAdmin GUI和以下命令到PostgreSQL

"C:\\Program Files\\PostgreSQL\\12\\bin\\psql.exe" 
--command " "\\copy public.\"Result\" 
FROM 'dummy.csv' 
DELIMITER ',' 
CSV HEADER ENCODING 'UTF8' 
QUOTE '\"' 
ESCAPE '''';""

but keep getting the following error :但不断收到以下错误

ERROR: extra data after the last expected column
CONTEXT:  COPY Result, line 2: «1,2,"a" 

What am I doing wrong?我究竟做错了什么?

The csv is not very 'clean': csv 不是很“干净”:

"F1", "F2", "F3"

1,2,"a"

3,4, "b"

3.4,2.4,"c"

There are spaces between the separator and the quotes which could give problems with some parsers.分隔符和引号之间有空格,这可能会给某些解析器带来问题。

Maybe try with the following first and see what this gives:也许先尝试以下方法,看看它给出了什么:

"F1","F2","F3"
1,2,"a"
3,4,"b"
3.4,2.4,"c"

You could even remove the quotes in this example.您甚至可以删除此示例中的引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM