From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | rloefgren(at)forethought(dot)net |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: serial, sequence, and COPY FROM |
Date: | 2006-09-12 19:01:59 |
Message-ID: | 20060912190159.GJ19178@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
rloefgren(at)forethought(dot)net wrote:
> All,
>
> I have a pipe delimited text file I'm trying to copy to a table. The
> file has 17 fields per line. The table has 18, with that last field
> (record) a serial with sequence. I have done:
> select setval('sequence_name_seq', 555, 'TRUE')
> but when I do: COPY tablename FROM '/path/to/file/file.txt' delimiter
> '|'
> the copy stops at the first row, insisting that it's missing data for
> the field record. Well, yeah...
> I can make this work with inserts but not with COPY FROM. What I've
> been doing is dumping it into a mysql table with an auto_increment
> field and then dumping that into a text file and using that for the
> COPY FROM; certainly clumsy. How might this be done?
Use a column list in the COPY command, something like
COPY tablename (col2, col3, col4) FROM '/foo/bar.txt';
where the col1 (which you leave out) contains the SERIAL stuff.
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2006-09-12 19:11:28 | Re: serial, sequence, and COPY FROM |
Previous Message | Michael Fuhr | 2006-09-12 18:54:23 | Re: serial, sequence, and COPY FROM |