Re: serial, sequence, and COPY FROM

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Brandon Aiken <BAiken(at)winemantech(dot)com>
Cc: rloefgren(at)forethought(dot)net, pgsql-general(at)postgresql(dot)org
Subject: Re: serial, sequence, and COPY FROM
Date: 2006-09-12 19:22:20
Message-ID: 20060912192220.GA57867@winnie.fuhr.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Sep 12, 2006 at 02:48:30PM -0400, Brandon Aiken wrote:
> Serial fields have a default value of nextval, so if you add an 18th
> field to your text file with DEFAULT in every record it should work as
> intended.

DEFAULT works with INSERT but not with COPY:

test=> CREATE TABLE foo (col1 integer, col2 integer, col3 serial);
NOTICE: CREATE TABLE will create implicit sequence "foo_col3_seq" for serial column "foo.col3"
CREATE TABLE
test=> COPY foo FROM stdin DELIMITER '|';
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1|2|DEFAULT
>> \.
ERROR: invalid input syntax for integer: "DEFAULT"
CONTEXT: COPY foo, line 1, column col3: "DEFAULT"

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Zlatko Matić 2006-09-12 20:54:17 program for graphical/schematical representation of relations between tables
Previous Message Scott Marlowe 2006-09-12 19:11:28 Re: serial, sequence, and COPY FROM