简体   繁体   中英

How to import a CSV file to a PostgreSQL table using pgAdmin

I am trying to import the following csv file (named dummy.csv):

"F1", "F2", "F3"

1,2,"a"

3,4, "b"

3.4,2.4,"c"

to PostgreSQL using the pgAdmin GUI with the following command:

"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':

"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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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