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 02E1BD1B3A8 for ; Thu, 24 Jun 2004 18:43:03 -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 22319-08 for ; Thu, 24 Jun 2004 21:42:56 +0000 (GMT) Received: from gatekeeper.fma.co.za (gatekeeper.fma.co.za [196.30.143.210]) by svr1.postgresql.org (Postfix) with ESMTP id 26EF2D1B380 for ; Thu, 24 Jun 2004 18:42:52 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by gatekeeper.fma.co.za (Postfix) with ESMTP id 93BF533020; Thu, 24 Jun 2004 23:42:49 +0200 (SAST) Received: from gatekeeper.fma.co.za ([127.0.0.1]) by localhost (gatekeeper.fma.co.za [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 26588-03; Thu, 24 Jun 2004 23:42:48 +0200 (SAST) Received: from [196.30.143.210] (gatekeeper.fma.co.za [196.30.143.210]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by gatekeeper.fma.co.za (Postfix) with ESMTP id 6FE593301F; Thu, 24 Jun 2004 23:42:41 +0200 (SAST) Message-ID: <40DB4AD0.8040805@sharp.fm> Date: Thu, 24 Jun 2004 23:42:40 +0200 From: Graham Leggett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040623 X-Accept-Language: en-za, en-us, en MIME-Version: 1.0 To: Phil Endecott Cc: pgsql-sql@postgresql.org Subject: Re: Normalising an existing table - how? References: <40DB229C.9040306@sharp.fm> <7184150@chezphil.org> In-Reply-To: <7184150@chezphil.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at fma.co.za X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/245 X-Sequence-Number: 18190 Phil Endecott wrote: >>- 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. > Change the order. Do the third step first: > > alter table T add column X integer; > update T set X = nextval(somesequence); > > Now do the first and second steps together: > > select X, MoneyColumn from T into NewTable; > > Is this the sort of thing you need? I think it is - though the select foo into NewTable part, does NewTable have to be empty first, or can it already exist? In my case NewTable has some rows in it already, as the database is currently partially normalised - I need to finish the job. Regards, Graham --