Skip site navigation (1) Skip section navigation (2)

Re: add serial no

From: Gaetano Mendola <mendola(at)bigfoot(dot)com>
To: Keith <siu_keith(at)hotmail(dot)com>
Subject: Re: add serial no
Date: 2004-08-24 21:07:09
Message-ID: 412BADFD.5030903@bigfoot.com (view raw or flat)
Thread:
Lists: pgsql-admin
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









In response to

pgsql-admin by date

Next:From: Steve CrawfordDate: 2004-08-24 21:48:42
Subject: Re: add serial no
Previous:From: andres barraDate: 2004-08-24 20:05:12
Subject: HELP pleaseeee!!!

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group