views:

38

answers:

1

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!

+2  A: 

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 ?)

Pascal MARTIN
I think you're right... but I could have sworn it was working *without* quotes before. A space after the comma wouldn't hurt any, would it?
Mark