Re: Mass Import/Generate PKs

From: Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar>
To: Hunter Hillegas <lists(at)lastonepicked(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Mass Import/Generate PKs
Date: 2004-11-06 21:13:27
Message-ID: 1099775607.71652.5.camel@taz.oficina
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

the simplest way to do it seems to be adding a SERIAL column to your
table, and then adding a primary key constraint:

1)insert data into table
2)ALTER TABLE <table> ADD id SERIAL;
3)ALTER TABLE <table> ADD CONSTRAINT <table>_pk PRIMARY KEY (id);

you can check the docs for the SERIAL type:
http://www.postgresql.org/docs/7.4/static/datatype.html#DATATYPE-SERIAL

On Sat, 2004-11-06 at 17:29, Hunter Hillegas wrote:

> That sounds nice and easy...
>
> So, I would do something like 'ALTER TABLE' to generate the PK column? What
> would be the best way to populate it? Is there an area of doco I should be
> looking at?
>
> Thanks,
> Hunter
>
>
> > From: Peter Eisentraut <peter_e(at)gmx(dot)net>
> > Date: Sat, 6 Nov 2004 21:21:25 +0100
> > To: Hunter Hillegas <lists(at)lastonepicked(dot)com>, PostgreSQL
> > <pgsql-general(at)postgresql(dot)org>
> > Subject: Re: [GENERAL] Mass Import/Generate PKs
> >
> > Hunter Hillegas wrote:
> >> I have a CSV file with 400,000 lines of email mailing list
> >> information that I need to migrate to a new PostgreSQL database.
> >>
> >> Each line has all the info I need except a PK (I usually use an int4
> >> column for a PK).
> >
> > You could import the file into PostgreSQL and add a primary key column
> > later.
> >
> > --
> > Peter Eisentraut
> > http://developer.postgresql.org/~petere/
> >
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ed L. 2004-11-06 21:56:03 Re: Mass Import/Generate PKs
Previous Message Pierre-Frédéric Caillaud 2004-11-06 21:11:15 Re: Trying to get postgres to use an index