Skip site navigation (1) Skip section navigation (2)

Re: Normalising an existing table - how?

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Normalising an existing table - how?
Date: 2004-06-24 21:08:06
Message-ID: 5.2.1.1.0.20040624170431.04384a70@pop6.sympatico.ca (view raw or flat)
Thread:
Lists: pgsql-sql
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  


In response to

Responses

pgsql-sql by date

Next:From: Graham LeggettDate: 2004-06-24 21:42:40
Subject: Re: Normalising an existing table - how?
Previous:From: Phil EndecottDate: 2004-06-24 20:55:47
Subject: Re: Normalising an existing table - how?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group