Re: Normalising an existing table - how?

From: "Phil Endecott" <spam_from_postgresql_sql(at)chezphil(dot)org>
To: Graham Leggett <minfrin(at)sharp(dot)fm>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Normalising an existing table - how?
Date: 2004-06-24 20:55:47
Message-ID: 7184150@chezphil.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

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?

--Phil.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Frank Bax 2004-06-24 21:08:06 Re: Normalising an existing table - how?
Previous Message Georgos Siganos 2004-06-24 20:43:08 Question about a CIDR based query