Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4E89463568E for ; Tue, 28 Jul 2009 18:13:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40141-06-5 for ; Tue, 28 Jul 2009 21:13:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.insa-lyon.fr (criges14.insa-lyon.fr [134.214.76.242]) by mail.postgresql.org (Postfix) with ESMTP id 78FF4635916 for ; Tue, 28 Jul 2009 18:12:13 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by smtp.insa-lyon.fr (Postfix) with ESMTP id 38618F11E0; Tue, 28 Jul 2009 23:12:11 +0200 (CEST) X-Virus-Scanned: SMTP at INSA-LYON Received: from smtp.insa-lyon.fr ([127.0.0.1]) by localhost (criges14.insa-lyon.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v8ZDLreyQQtU; Tue, 28 Jul 2009 23:12:09 +0200 (CEST) Received: from [127.0.0.1] (liris.univ-lyon1.fr [134.214.142.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: nhandrianar) by smtp.insa-lyon.fr (Postfix) with ESMTPSA id 88C84F11D9; Tue, 28 Jul 2009 23:12:08 +0200 (CEST) Message-ID: <4A6F695D.7070000@free.fr> Date: Tue, 28 Jul 2009 23:10:53 +0200 From: nha Organization: Lyon, Rhone, France User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: =?ISO-8859-1?Q?=22Gau=2C_Hans-J=FCrgen=22?= CC: PgSQL-sql Subject: Re: sql-porting-problem oracle to postgresql with UPDATE/IS NOT NULL References: <670F563845D6B34189933C9C7322B4872C0568@LV-MX-00002-V02.LV.ads.niedersachsen.de> <215A7F0B-D033-4C12-B80E-4A4E4613FD41@comcast.net> In-Reply-To: <215A7F0B-D033-4C12-B80E-4A4E4613FD41@comcast.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=-10 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/137 X-Sequence-Number: 32878 Hello, Le 28/07/09 14:25, Daryl Richter a écrit : > > On Jul 28, 2009, at 5:58 AM, Gau, Hans-Jürgen wrote: > >> hello list, >> i have some problems with an sql-statement which runs on oracle but >> not on postgresql (i want update only if result of SELECT is not >> empty, the SELECT-queries are identical): >> >> UPDATE table1 t1 >> SET (t1.id) = >> (SELECT h.id FROM table2 t2,table3 t3, table1 t1 >> WHERE t3.field = t2.field >> AND t2.id = t1.id >> AND t1.id <> t3.id) >> WHERE >> (SELECT h.id FROM table2 t2,table3 t3, table1 t1 >> WHERE t3.field = t2.field >> AND t2.id = t1.id >> AND t1.id <> t3.id) IS NOT NULL; >> > Try this: > > UPDATE table1 t1 [...] > WHERE > EXISTS (SELECT 1 FROM table2 t2,table3 t3, table1 t1 > WHERE t3.field = t2.field > AND t2.id = t1.id > AND t1.id <> t3.id > > AND h.id IS NOT NULL); > Beyond the solution brought by Daryl Richter, it seems that "h" is an unbound alias in the original (and also in the suggested) query. Some clarification would be helpful for further investigation. Regards. -- nha / Lyon / France.