I am using postgreSQL version 13.0.1. (I have to use postgre)
Table Structure
CREATE TABLE public.orders
(
key integer NOT NULL,
skey integer NOT NULL,
status character(1) COLLATE pg_catalog."default" NOT NULL,
price numeric(15,2) NOT NULL,
date date NOT NULL,
priority character(15) COLLATE pg_catalog."default" NOT NULL,
man character(15) COLLATE pg_catalog."default" NOT NULL,
priority2 integer NOT NULL,
comment character varying(79) COLLATE pg_catalog."default" NOT NULL
)
TABLESPACE pg_default;
ALTER TABLE public.orders
OWNER to postgres;
CSV File contents. the first line is the header, the second line is data:
key ,skey, status , price , date ,priority2 ,man, priority ,comment
1 ,2 , 3 , 45.33 , 1992-02-21 ,4-NOT SPECIFIED ,man#000000058 , 0 ,ggle. so, whatever you say.
My Query
COPY public.orders FROM 'D:\orders.csv' WITH (format csv,Header);
The Error:
ERROR: extra data after last expected column
CONTEXT: COPY orders, line 3: "1,2,3,45.33,1992-02-21,4-NOT SPECIFIED,man#000000058,0,ggle. so, whatever you say.
"
SQL state: 22P04
Error is probably due to the last column that has a string (ggle. so, whatever you say.) with no " " to demark it as a string. It also has a comma in it.
My desired output is to have the query complete successfully with the last column read as a whole string. I am also not allowed to change the data in the file.
I have tried advice from these links:
Importing CSV and commas in string values
https://www.postgresql.org/docs/13/sql-copy.html
but I still ended up with the query and error as mentioned above. Please enlighten me.