X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id A1E7011F61E0 for ; Fri, 7 Apr 2006 17:34:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36586-07 for ; Fri, 7 Apr 2006 17:34:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 58ECA11F6026 for ; Fri, 7 Apr 2006 17:34:49 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Fri, 7 Apr 2006 20:34:49 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 07 Apr 2006 15:34:49 -0500 Subject: Re: How to copy data between joined columns? From: Scott Marlowe To: Bryce Nesbitt Cc: pgsql-sql@postgresql.org In-Reply-To: <4436CC56.3040707@obviously.com> References: <4436CC56.3040707@obviously.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1144442088.32269.31.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 07 Apr 2006 15:34:49 -0500 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.102 required=5 tests=[AWL=0.101, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.102 X-Spam-Level: X-Archive-Number: 200604/54 X-Sequence-Number: 24863 On Fri, 2006-04-07 at 15:32, Bryce Nesbitt wrote: > I have a need to copy/update data from one column to another, based on a > join condition. Is this easy to do in pure SQL? I have google'ed > without luck for a easy solution (that's not Microsoft specific, that > is). For example: > > postgres=# > select xx_thing.date_start,xx_note.created_date > from xx_thing > join xx_issue using (thing_id) join xx_note using (issue_id) > where xx_note.created_date is not null; > > date_start | created_date > ----------------+--------------------- > 2006-03-17 | 1900-01-01 > (...many... rows) > > I need to copy date_start to created_date, for all records that meet a > particular where condition. If it's for the same rows in the same table, you're overworking it. update table set field1=field2 where somecondition;