X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DFF4D5E472F for ; Thu, 2 Sep 2004 10:16:47 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 49628-07 for ; Thu, 2 Sep 2004 13:16:45 +0000 (GMT) Received: from web12707.mail.yahoo.com (web12707.mail.yahoo.com [216.136.173.244]) by svr1.postgresql.org (Postfix) with SMTP id 3235C5E471A for ; Thu, 2 Sep 2004 10:16:43 -0300 (ADT) Message-ID: <20040902131647.26244.qmail@web12707.mail.yahoo.com> Received: from [195.29.99.22] by web12707.mail.yahoo.com via HTTP; Thu, 02 Sep 2004 06:16:47 PDT Date: Thu, 2 Sep 2004 06:16:47 -0700 (PDT) From: Reply-To: ogjunk-pgjedan@yahoo.com Subject: copy old column's values to new column To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200409/24 X-Sequence-Number: 18870 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