Skip site navigation (1) Skip section navigation (2)

Re: COPY command and serial columns

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: stafford(at)marine(dot)rutgers(dot)edu
Cc: PostgreSQL List - Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: COPY command and serial columns
Date: 2010-11-06 15:41:53
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
"Wm.A.Stafford" <stafford(at)marine(dot)rutgers(dot)edu> writes:
> I am trying to use COPY to load some data.  I am not using a list of 
> column names in the COPY command.  The table I am loading has 80 
> character varying columns and a primary key defined as: id serial 

> The id field is not in the data being loaded so COPY gives the message:
> ERROR:  missing data for column "id"

> I don't want to use a column list because this table is subject to a lot 
> of change and a column list would be yet another possible point of 
> failure if it has to be changed to keep up with table changes.

> Is there anyway to load this data without specifying a column list?

Nope, sorry, COPY lacks the "READ MY MIND" option.  If the incoming
data doesn't include every column of the table, you have to specify
a column list to tell it which columns the data does include.

Possibly you could make your code robust against table alterations by
having it look into the system catalogs to get the current column
list.  Then it could leave out the column name(s) it knows a-priori
aren't in the data.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Gregor NovakDate: 2010-11-06 20:07:15
Subject: migrating from linux to Windows
Previous:From: LewDate: 2010-11-06 15:26:03
Subject: Re: Data Types

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group