From: Bruno Wolff III <bruno@wolff.to>
To: ogjunk-pgjedan@yahoo.com
Cc: pgsql-sql@postgresql.org
Subject: Re: copy old column's values to new column
Date: Thu, 2 Sep 2004 08:51:08 -0500
Message-ID: <20040902135108.GA12899@wolff.to> (raw)
In-Reply-To: <20040902131647.26244.qmail@web12707.mail.yahoo.com>
References: <20040902131647.26244.qmail@web12707.mail.yahoo.com>
On Thu, Sep 02, 2004 at 06:16:47 -0700,
ogjunk-pgjedan@yahoo.com wrote:
> 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?
Assuming you are just copying "value" to "display_value", can't you just do:
UPDATE preference_value SET display_value = value;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, ogjunk-pgjedan@yahoo.com
Subject: Re: copy old column's values to new column
In-Reply-To: <20040902135108.GA12899@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox