Copying data from a tab delimited file into a table

Поиск
Список
Период
Сортировка
Искать

Copying data from a tab delimited file into a table

От:
Carol Walter <carol.walter@sbcglobal.net>
Дата:
I'm trying to copy the data from a tab delimited file into a postgres table. The table has a primary key that's designated as a serial data type. When I try to do the copy, it "blows up" unless I put a integer number in the field where the primary key will be. That defeats the purpose of designating this field as serial. When I put data into that field the copy works but an insert statement fails because it says there is a duplicate key. How can I get the data from this file into my table and still have the key field designated with a "serial data type"?

Thanks,
Carol

Re: Copying data from a tab delimited file into a table

От:
James David Smith <james.david.smith@gmail.com>
Дата:
On 11 February 2014 17:13, Carol Walter  wrote:
> I'm trying to copy the data from a tab delimited file into a postgres table. The table has a primary key that's designated as a serial data type. When I try to do the copy, it "blows up" unless I put a integer number in the field where the primary key will be. That defeats the purpose of designating this field as serial. When I put data into that field the copy works but an insert statement fails because it says there is a duplicate key. How can I get the data from this file into my table and still have the key field designated with a "serial data type"?
>
> Thanks,
> Carol
>

Sorry, should have sent the below to the whole list:

Hi Carol,

Why not import the data first, and then add the serial column
afterwards? That's what I'd do.

James

Re: Copying data from a tab delimited file into a table

От:
Carol Walter <carol.walter@sbcglobal.net>
Дата:
FYI, I was able to do this with the COPY command which takes a field list as arguments. I don't know if the "\copy" command does or not, but I was able to use COPY and it worked.

On Feb 11, 2014, at 12:13 PM, Carol Walter wrote:

> I'm trying to copy the data from a tab delimited file into a postgres table. The table has a primary key that's designated as a serial data type. When I try to do the copy, it "blows up" unless I put a integer number in the field where the primary key will be. That defeats the purpose of designating this field as serial. When I put data into that field the copy works but an insert statement fails because it says there is a duplicate key. How can I get the data from this file into my table and still have the key field designated with a "serial data type"?
> 
> Thanks,
> Carol
> 
> -- 
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice


Re: Copying data from a tab delimited file into a table

От:
Luca Ferrari <fluca1978@infinito.it>
Дата:
On Tue, Feb 11, 2014 at 8:21 PM, Carol Walter
 wrote:
> FYI, I was able to do this with the COPY command which takes a field list as arguments. I don't know if the "\copy" command does or not, but I was able to use COPY and it worked.

Yes it does (see http://www.postgresql.org/docs/current/static/app-psql.html).

Luca

FAQ