import a CSV file with JSONB into postgresql 14

56 Views Asked by At

I am looking to load this two rows below from a csv file with second value being JSONB [column name: details].

1,"{""fields0"": [""is_enabled""], ""t_id"": ""Lcum"", ""fields1"": [""is_enabled""], ""m_id"": ""xdrd""}",completed,2020-07-22 15:24:31.083853+00,2020-07-22 15:24:31.2443+00
2,"{""fields0"": [""is_enabled""], ""t_id"": ""Lcum"", ""fields1"": [""is_enabled""], ""m_id"": ""xdrd""}",completed,2020-07-22 15:25:15.16227+00,2020-07-22 15:25:15.317736+00
\copy task (id,details,status,time_started,time_completed) FROM '0000-2893fb23.parquet.csv' csv header escape E'\n' quote '"';

the error i receive

"ERROR: extra data after last expected column"

can someone advise what i am doing wrong

1

There are 1 best solutions below

1
Maimoona Abid On

According to error which you are encountering there may be an issue with the data format in your CSV file, or it may not be corresponding to the table which you created, so here are few things which you should check;

Make sure your CSV file doesn't contain any extra columns or information that isn't specified in the "task" table. Your CSV should have the same number of columns as the structure of the table, according to PostgreSQL.

Make sure your CSV file doesn't have any extra delimiters or stray commas that might be causing PostgreSQL to interpret the data erroneously.

Verify that the CSV file ("0000-2893fb23.parquet.csv") you are attempting to import is in fact in the proper format and does not contain any unusual characters or formatting issues.