Importing data - Mailing list pgsql-general

From Patrick Nelson
Subject Importing data
Date
Msg-id 4165C48DE9A0D211B6400800095C585F172DE8@WASHINGTON
Whole thread Raw
Responses Re: Importing data
List pgsql-general
If I have a table that has a column called id that I would like to have a
incrementing field.  However, the data that I'm importing doesn't have that
field.  I though that using a sequence would work, but that doesn't seem to
do it, here was the setup:

  CREATE SEQUENCE "mss_id_seq" start 1 increment 1 maxvalue 2147483647
minvalue 1 cache 1;
  SELECT nextval ('"mss_id_seq"');
  CREATE TABLE "mss" (
   "id"  int4         DEFAULT nextval('mss_id_seq'::text) NOT NULL,
   "ind" int4         NOT NULL,
   "syb" varchar(5)   NOT NULL,
   "nam" varchar(50)  NOT NULL,
   "yts" varchar(50)  NOT NULL,
   "bys" int4         NOT NULL,
   "byr" int4         NOT NULL,
   "hld" int4         NOT NULL,
   "ser" int4         NOT NULL,
   "ses" int4         NOT NULL,
   "tor" int4         NOT NULL,
   "wor" numeric(5,2) NOT NULL,
   "dat" varchar(50)  NOT NULL,
  );

Then I import using psql command:

  COPY mss FROM '/subset.csv' USING DELIMITERS ',';

Which imports a file like:

  ,1,SLWS,SLWS DATA,$489.18M,6,1,1,0,0,8,1.37,Sat Jun 29 12:42:47 PDT 2002
  ,2,SRDE,SRDE DATA,$232.30M,0,0,2,0,0,2,3,Sat Jun 29 12:43:00 PDT 2002
  ...

However, id doesn't get populated with a sequence of numbers.  Note that the
1 and 2 of the above import file is being properly dumped into ind, even
though I have to add "," to the beginning of each line.  So I think that I
don't really get it.  Hmm...

What I would like the data to look like (from the above import) is like:

 id ind syb  nam       yts       bys byr hld ser ses tor wor  dat
 -- --- ---- --------- --------  --- --- --- --- --- --- ----
----------------------------
 1  1   SLWS SLWS DATA $489.18M  6   1   1   0   0   8   1.37 Sat Jun 29
12:42:47 PDT 2002
 2  2   SRDE SRDE DATA $232.30M  0   0   2   0   0   2   3    Sat Jun 29
12:43:00 PDT 2002

Where I could make the id as the primary key.  What don't I get?

pgsql-general by date:

Previous
From: Amin Abdulghani
Date:
Subject: Re: postgres 7.2.1 parse bug
Next
From: nconway@klamath.dyndns.org (Neil Conway)
Date:
Subject: Re: Importing data