Re: add serial no - Mailing list pgsql-admin

From Uwe C. Schroeder
Subject Re: add serial no
Date
Msg-id 200408241143.08959.uwe@oss4u.com
Whole thread Raw
In response to add serial no  ("Keith" <siu_keith@hotmail.com>)
Responses Adding Serial Type
List pgsql-admin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sunday 22 August 2004 02: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.

Create a table with the same structure as your original table, just add a

sid int4 serial

column to it. (sid can be any column name you want it to be) The serial column
has to be at the end!
Then do a
INSERT INTO <new table> SELECT FROM <old table>

The serial column will automatically be set to 1,2,3,4,5 etc.
After that check if all the data made it to the new table and then you can
drop the old table and rename the new table to the name of the old table.

As usual I'd make a backup of the original table before doing all this.

> 2. Is there any library to translate digit number to English, I mean
> translate '1234' to 'one thousand two hundred thirty four'.. Pls help.

Sorry, can't help with that one.


    UC

- --
Open Source Solutions 4U, LLC    2570 Fleetwood Drive
Phone:  +1 650 872 2425        San Bruno, CA 94066
Cell:   +1 650 302 2405        United States
Fax:    +1 650 872 2417
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFBK4w8jqGXBvRToM4RAm5MAJ0c5ygo1V9ISdn7nOy51rHazWbnDACg0QBF
1nlwxalbrc8vVb64dxk7QgE=
=hi8w
-----END PGP SIGNATURE-----


pgsql-admin by date:

Previous
From: Naomi Walker
Date:
Subject: Re: mySQL to postgreSQL: Request for pointers to perl/phpresources for app conversion.
Next
From: "andres barra"
Date:
Subject: HELP pleaseeee!!!