X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1A7EAD1B3A8 for ; Thu, 24 Jun 2004 18:08:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08776-06 for ; Thu, 24 Jun 2004 21:08:42 +0000 (GMT) Received: from tomts25-srv.bellnexxia.net (tomts25-srv.bellnexxia.net [209.226.175.188]) by svr1.postgresql.org (Postfix) with ESMTP id EB42CD1B343 for ; Thu, 24 Jun 2004 18:08:38 -0300 (ADT) Received: from acer.sympatico.ca ([65.95.129.144]) by tomts25-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20040624210838.BSAL28143.tomts25-srv.bellnexxia.net@acer.sympatico.ca> for ; Thu, 24 Jun 2004 17:08:38 -0400 Message-Id: <5.2.1.1.0.20040624170431.04384a70@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Thu, 24 Jun 2004 17:08:06 -0400 To: pgsql-sql@postgresql.org From: Frank Bax Subject: Re: Normalising an existing table - how? In-Reply-To: <40DB229C.9040306@sharp.fm> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.2 tagged_above=0.0 required=5.0 tests=RCVD_IN_NJABL, RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200406/244 X-Sequence-Number: 18189 At 02:51 PM 6/24/04, Graham Leggett wrote: >I have an existing table containing a column in it containing a money >value. I would like to normalise this column into a separate table, as the >money value is to be expanded to contain a tax value, etc. > >I have been trying to find a SQL query that will do the following: > >- Select the money column from the table >- Populate the new normalised table with each row containing the value >from the original money column >- Write the primary keys of the new rows in the normalised table, back to >a new column in the original table added for this purpose. > >This third step I am struggling with - can anyone suggest a query that >might achieve the writing back of the primary key to the original table? Do all three steps in one command: create table newtable as (select key1, key2, money from oldtable); Frank