Re: add serial no

Поиск
Список
Период
Сортировка
От Steve Crawford
Тема Re: add serial no
Дата
Msg-id 200408241448.42337.scrawford@pinpointresearch.com
обсуждение исходный текст
Ответ на add serial no  ("Keith" <siu_keith@hotmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Gaetano Mendola
Дата:
Сообщение: Re: add serial no
Следующее
От: Lawrence C
Дата:
Сообщение: Re: [GENERAL] Dump and Restore