copy old column's values to new column

From: <ogjunk-pgjedan(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: copy old column's values to new column
Date: 2004-09-02 13:16:47
Message-ID: 20040902131647.26244.qmail@web12707.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I need some basic SQL help. I added a new column to an existing table,
and now I need to copy values from one of the old columns to this new
columns.

I need something like this:

FOR pvId IN SELECT id FROM preference_value LOOP
update preference_value SET display_value = (select value from
preference_value where id=pvId) where id=pvId;
END LOOP;

I tried running this from psql, but it didn't work (I suspect FOR can
be used in functions, which I don't know how to write in PG, yet).

Is there a simple way to do this?

Thanks,
Otis

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2004-09-02 13:50:17 Re: PRIMARY KEY and INDEX
Previous Message Tom Lane 2004-09-01 22:41:25 Re: Defining Field Types with view