Re: add serial no

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: "Keith" <siu_keith(at)hotmail(dot)com>, <pgsql-admin(at)postgresql(dot)org>
Subject: Re: add serial no
Date: 2004-08-24 21:48:42
Message-ID: 200408241448.42337.scrawford@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Sunday 22 August 2004 2:47 am, 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.
>
> 2. Is there any library to translate digit number to English, I
> mean translate '1234' to 'one thousand two hundred thirty four'..
> Pls help.
>
> regards

Going from memory (and note, this will only give you unique numbers -
they won't be in any specific order)...

create sequence foo_sequence;

alter table foo add column (serialnumber bigint);

alter table foo alter column serialnumber set default
nextval('foo_sequence');

update foo set serialnumber = nextval('foo_sequence') where
serialnumber is null;

alter table foo alter column serialnumber set not null;

Cheers,
Steve

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Andrew Farmer 2004-08-25 01:41:17 7.3.4 Table corruption
Previous Message Gaetano Mendola 2004-08-24 21:07:09 Re: add serial no