pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedcopy old column's values to new column
2+ messages / 2 participants
[nested] [flat]
* copy old column's values to new column
@ 2004-09-02 13:16 ogjunk-pgjedan@yahoo.com
0 siblings, 1 reply; 2+ messages in thread
From: ogjunk-pgjedan@yahoo.com @ 2004-09-02 13:16 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: copy old column's values to new column
@ 2004-09-02 13:51 Bruno Wolff III <bruno@wolff.to>
parent: ogjunk-pgjedan@yahoo.com
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Wolff III @ 2004-09-02 13:51 UTC (permalink / raw)
To: ogjunk-pgjedan@yahoo.com; +Cc: pgsql-sql
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;
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2004-09-02 13:51 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-09-02 13:16 copy old column's values to new column ogjunk-pgjedan@yahoo.com
2004-09-02 13:51 ` Bruno Wolff III <bruno@wolff.to>
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