Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id C0803475E55 for ; Fri, 7 Jun 2002 11:23:18 -0400 (EDT) Received: from smtp011.mail.yahoo.com (smtp011.mail.yahoo.com [216.136.173.31]) by postgresql.org (Postfix) with SMTP id 4883347667B for ; Fri, 7 Jun 2002 10:22:36 -0400 (EDT) Received: from unknown (HELO saturn.janwieck.net) (janwieck@192.233.92.205 with login) by smtp.mail.vip.sc5.yahoo.com with SMTP; 7 Jun 2002 14:22:39 -0000 Received: (from wieck@localhost) by saturn.janwieck.net (8.11.2/8.11.2) id g57EK5B27878; Fri, 7 Jun 2002 10:20:05 -0400 From: Jan Wieck Message-Id: <200206071420.g57EK5B27878@saturn.janwieck.net> Subject: Re: UPDATE ... FROM vs standard SQL In-Reply-To: <200206071133.23179.dev@archonet.com> from Richard Huxton at "Jun 7, 2002 11:33:23 am" To: Richard Huxton Date: Fri, 7 Jun 2002 10:20:05 -0400 (EDT) Cc: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200206/70 X-Sequence-Number: 8035 Richard Huxton wrote: > I've been happily using statements like > UPDATE a SET flag=1 FROM b WHERE a.id=b.id AND b.foo='x'; > > While PG's FROM extension makes life simple, I can't believe there's not a way > to do an update on a join using standard SQL. The two options I can think of > are: > > 1. using a sub-select > UPDATE a SET flag=1 WHERE a.id IN (SELECT id FROM b WHERE b.foo='X'); > Which is fine, but no good for mysql, hits PG's speed issue with IN and a bit > clumsy for more complicated examples. > > 2. building an updatable view. If your goal is to gain better portability for your app, go with the subselect. Updatable views, especially if they do joins, are far less supported (if at all). Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #