X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 162935E46C2 for ; Tue, 24 Aug 2004 18:31:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92172-04 for ; Tue, 24 Aug 2004 21:31:25 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 930F25E40BA for ; Tue, 24 Aug 2004 18:31:24 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i7OLVOLq093952 for ; Tue, 24 Aug 2004 21:31:24 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i7OL7Cla084870 for pgsql-admin@postgresql.org; Tue, 24 Aug 2004 21:07:13 GMT From: Gaetano Mendola X-Newsgroups: comp.databases.postgresql.admin Subject: Re: add serial no Date: Tue, 24 Aug 2004 23:07:09 +0200 Organization: PYRENET Midi-pyrenees Provider Lines: 53 Message-ID: <412BADFD.5030903@bigfoot.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@pyrenet.fr To: Keith User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en In-Reply-To: X-Enigmail-Version: 0.85.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime To: pgsql-admin@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/242 X-Sequence-Number: 14637 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