Re: add serial no - Mailing list pgsql-admin

From Steve Crawford
Subject Re: add serial no
Date
Msg-id 200408241448.42337.scrawford@pinpointresearch.com
Whole thread Raw
In response to add serial no  ("Keith" <siu_keith@hotmail.com>)
List 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


pgsql-admin by date:

Previous
From: Gaetano Mendola
Date:
Subject: Re: add serial no
Next
From: Lawrence C
Date:
Subject: Re: [GENERAL] Dump and Restore