Re: [GENERAL] Incrementing a Serial Field

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Bob Kruger <bkruger(at)mindspring(dot)com>, pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Incrementing a Serial Field
Date: 1998-11-09 16:32:09
Message-ID: l03110701b26cc8f67da9@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 19:07 +0200 on 9/11/98, Bob Kruger wrote:

>
> I do have two questions. Firstly, I have one table that is updated from a
> text file. This table also has a serial field that is incremented with
> each new record. Is there a way to use the copy command to have that field
> automatically updated - e.g. copy table_one from '/data/files/input.txt'
> using delimiters '|' ?
>
> So far, I can get this text file to import just fine when using a table
> without a serial field, but as of yet not had any luck in importing it into
> a table that has a serial field.

Assuming the serial field is defined as a NOT NULL DEFAULT nextval( 'seq'
), the simplest way is to put nulls for that field in the text file. That
is, suppose it is the third field in your table, you write

data for field1|data for field 2|\N|data for field4...

The \N (capital N) stands for null, and will cause Postgres to use the
default value for that field.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bob Kruger 1998-11-09 17:07:57 Incrementing a Serial Field
Previous Message Bill Moore 1998-11-09 16:20:25 info