pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gaetano Mendola <mendola@bigfoot.com>
To: Keith <siu_keith@hotmail.com>
Subject: Re: add serial no
Date: Tue, 24 Aug 2004 23:07:09 +0200
Message-ID: <412BADFD.5030903@bigfoot.com> (raw)
In-Reply-To: <BAY12-DAV10Jgzg8MTb000098bb@hotmail.com>
References: <BAY12-DAV10Jgzg8MTb000098bb@hotmail.com>

Keith wrote:

> Dear All,
>  
> Someone can help me to solve the below problems
>  
> 1. I create a table for a period of time, there is huge records already 
> posted.
> I would like to alter table and add serial primary key on that table.  
> It's impossible to add serial no by hand. Please adv  how can I add the 
> serial number automatically.


Just to inform you that with the future 8.0 postgresl version you can
do this task easily:

kalman=# select * from test;
 field_1
---------
       3
       5
       7
       6
       8
(5 rows)

kalman=# alter table test add column pk serial primary key;
NOTICE:  ALTER TABLE will create implicit sequence "test_pk_seq" for serial column "test.pk"
NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index "test_pkey" for table "test"
ALTER TABLE
kalman=# select * from test;
 field_1 | pk
---------+----
       3 |  1
       5 |  2
       7 |  3
       6 |  4
       8 |  5
(5 rows)




Regards
Gaetano Mendola











view thread (4+ messages)  latest in thread

Message-ID: <412BADFD.5030903@bigfoot.com>
Permalink:  ../412BADFD.5030903@bigfoot.com/
Also on:    postgresql.org/message-id/412BADFD.5030903@bigfoot.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mendola@bigfoot.com, siu_keith@hotmail.com
  Subject: Re: add serial no
  In-Reply-To: <412BADFD.5030903@bigfoot.com>
  References: <BAY12-DAV10Jgzg8MTb000098bb@hotmail.com> <412BADFD.5030903@bigfoot.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox