Re: The COPY command and csv files

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "E(dot) Matthew Finnin" <emf(dot)storage(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: The COPY command and csv files
Date: 2006-04-18 14:02:09
Message-ID: 12818.1145368929@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"E. Matthew Finnin" <emf(dot)storage(at)gmail(dot)com> writes:
> This is the error I get after using the copy command:
> ERROR: missing data for column "isocode"
> CONTEXT: COPY pwt61_oecd, line 1:

> This is the first line of the csv file, where the error is occuring:
> "Australia","AUS","1950","8434.0650803","0.8931999704","0.515977685","1836.3303946","60.365553134","27.690222887","7.9941116957","57.767319935","53.853430186","73.898773273","61.642604011","47.850011457",na,"31.64033517","95.021059091","9113.8072046","9173.8190347","10576.40502","22078.709149","9988.2503259","19.331539711","65.924922543","13.104642709","26.200404435",na

Is that really exactly what the error message looks like? Because what
it should be echoing back after "line 1:" is the first line of the file.
Here's a trivial example using data entered from the keyboard:

regression=# create table t1 (f1 text,f2 text);
CREATE TABLE
regression=# copy t1 from stdin csv;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> "A","B"
>> \.
regression=# copy t1 from stdin csv;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> "A"
>> \.
ERROR: missing data for column "f2"
CONTEXT: COPY t1, line 1: ""A""
regression=# copy t1 from stdin csv;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>>
>> \.
ERROR: missing data for column "f2"
CONTEXT: COPY t1, line 1: ""
regression=#

I'm wondering if maybe you're making some simple mistake that's got
nothing to do with the file format, but rather you're pointing COPY
at the wrong file or some such. The behavior seems consistent with
the idea that COPY is seeing an empty line as the first line of data.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Robert Landsmeer 2006-04-18 14:05:48 Find all foreign keys and dropping them from a script.
Previous Message Sean Davis 2006-04-18 10:50:40 Re: The COPY command and csv files