Re: add serial no

From: "Uwe C(dot) Schroeder" <uwe(at)oss4u(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 18:43:08
Message-ID: 200408241143.08959.uwe@oss4u.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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-----

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message andres barra 2004-08-24 20:05:12 HELP pleaseeee!!!
Previous Message Bruno Wolff III 2004-08-24 17:42:08 Re: PostgreSQL Migration of databases 7.2 to 7.4