mpen
mpen

Reputation: 283355

How to import a CSV?

I've got a CSV file that looks like this:

id, name
0, A.D. TRAMONTANA
1, Abarth
2, Abbot-Detroit
3, AC
...

I'm trying to import it into my table via phpPgAdmin.

It gives me this error:

SQL error:

ERROR:  column "id, name" of relation "app_vehiclemake" does not exist
LINE 1: INSERT INTO "public"."app_vehiclemake" ("id, name") VALUES (...
                                                ^

In statement:
INSERT INTO "public"."app_vehiclemake" ("id, name") VALUES ('0, A.D. TRAMONTANA')

It looks like it's quoting "id, name" as one column name. Not really sure why... what format should my CSV be in? Can't find any documentation on this!

Upvotes: 0

Views: 4165

Answers (1)

Pascal MARTIN
Pascal MARTIN

Reputation: 401182

The PHP fgetcsv() function, which is often used to read a line from a CSV file, expects :

  • , as a delimiter between fields
  • " as enclosure, for each data of each field.

So maybe just putting double-quotes arround each piece of data would work ?


Something like this, I'd say :
"id","name"
"0","A.D. TRAMONTANA"
"1","Abarth"
"2","Abbot-Detroit"
"3","AC"

(Well, not sure... But might be worth a try ?)

Upvotes: 2

Related Questions