copy old column"s values to new column
am 02.09.2004 15:16:47 von ogjunk-pgjedan
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
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
Re: copy old column"s values to new column
am 02.09.2004 15:51:08 von Bruno
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;
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match