0

Its a Django app in which im loading a CSV , table gets created OK but the CSV copying to PSQL fails with ERROR =

psycopg2.DataError: extra data after last expected column
CONTEXT:  COPY csvfails, line 1:

Questions already referred - "extra data after last expected column" while trying to import a csv file into postgresql

Have tested multiple times , with CSV of different Column Counts , am sure now the COLUMN Count is not the issue , its the content of the CSV file. As when i change the Content and upload same CSV , table gets created and dont get this error . Content of CSV file that fails is as seen below. Kindly advise what in this content prompts - psycopg2/psql/postgres to give this error .

No as suggested in the comment cant paste even a single row of the CSV file , the **imgur** image add-in , wont allow , not sure what to do now ? 

Seen below screenshots from psql - cli - the table had been created with the correct columns count , still got the error .

enter image description here

enter image description here

EDIT_1 - Further while saving on my ubuntu , using libre office , unchecked the - Separator Options >> Separated By >> TAB and SEMICOLON . This CSV then saved with only -- Separator Options >> COMMA.

The python line of code which might be the culprit is =


with open(path_csv_for_psql, 'r') as f:
            next(f)  # Skip the header row.
            csv_up_cursor.copy_from(f, str(new_table_name), sep=',')
            conn.commit() 

I thought i read somewhere that the - separator parameter passed to copy_from which is default = sep=',') , could be the issue ?

Rohit Dhankar
  • 1,574
  • 18
  • 25
  • 1
    Instead of screenshots, it would be helpful to show the actual data. The CSV is short enough that you should be able to include it. We can't tell from the link if it's being quoted correctly when it's saved as CSV. – Jeremy Aug 15 '19 at 15:24
  • @Jeremy - sorry the imgur - image add-in doesnt allow me to paste from the CSV . – Rohit Dhankar Aug 15 '19 at 16:35

0 Answers0