pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Uwe C. Schroeder <uwe@oss4u.com>
To: Keith <siu_keith@hotmail.com>
To: pgsql-admin@postgresql.org
Subject: Re: add serial no
Date: Tue, 24 Aug 2004 11:43:08 -0700
Message-ID: <200408241143.08959.uwe@oss4u.com> (raw)
In-Reply-To: <BAY12-DAV10Jgzg8MTb000098bb@hotmail.com>
References: <BAY12-DAV10Jgzg8MTb000098bb@hotmail.com>

-----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-----




view thread (4+ messages)  latest in thread

Message-ID: <200408241143.08959.uwe@oss4u.com>
Permalink:  ../200408241143.08959.uwe@oss4u.com/
Also on:    postgresql.org/message-id/200408241143.08959.uwe@oss4u.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: uwe@oss4u.com, siu_keith@hotmail.com
  Subject: Re: add serial no
  In-Reply-To: <200408241143.08959.uwe@oss4u.com>
  References: <BAY12-DAV10Jgzg8MTb000098bb@hotmail.com> <200408241143.08959.uwe@oss4u.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox