0
votes

I am trying to import CSV file into the postgreSQL database table. But i am getting an error :

ERROR: missing data for column "portion" SQL state: 22P04 Context: COPY fooditems, line 2: "Chicken Curry,100,132,4.5,11.4,7.6"

SQLCommands i am using is :

create table FoodItems
    (Food_item      varchar(20),
     Portion        varchar(7),
     Calories       varchar(7),
     Carbohydrates  varchar(7),
     Protein        varchar(7),
     Total_Fat      varchar(7),
     primary key (Food_item));



COPY FoodItems (Food_item,Portion,Calories,Carbohydrates,Protein,Total_Fat) 
FROM 'D:\convertcsv.csv' WITH DELIMITER ';' CSV HEADER;

link for the html page: http://www.buzzle.com/articles/indian-food-calories.html

I need the data in table so that i can use it for back-end for an app. I don't understand what seems to be the issue.

Hope someone can help me. Thanks in advance.

1
Can you show a screenshot of your CSV File ?? - Vivek S.

1 Answers

0
votes

The problem is with the CSV file.To test just change DELIMITER ';' to DELIMITER ',' and run your COPY Command

Ie.

COPY FoodItems (Food_item,Portion,Calories,Carbohydrates,Protein,Total_Fat) 
FROM 'D:\food.csv' WITH DELIMITER ',' CSV HEADER;