Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id A28861C0B198 for ; Fri, 20 Jul 2012 11:14:09 -0300 (ADT) Received: from mail-qc0-f174.google.com ([209.85.216.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SsDy2-0006FN-1u for pgsql-sql@postgresql.org; Fri, 20 Jul 2012 14:14:08 +0000 Received: by qcro28 with SMTP id o28so2334369qcr.19 for ; Fri, 20 Jul 2012 07:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=8d+jIwVEkbUCBEi2lUgF0IuKPDT4a5/+miBHWMmqkFk=; b=pbmn0Kpo2x9CLoIIEz63nDnOAEXGnQBB0ghgA8gKZNiy4J51fvbkGZ4h5A9mc9p4Px WTmpm9O1Gkf/s3MxN09wQXLcTg6xn23YW++S5t3wEXNF/KGg07Oh+T1NSPF4DWJwPbgD QX/FYwt4oYblhdIvqad7hyvgSEcXgVR8D0xTN3sThe+5op4LsFJ5Fato0VfH0lBfZA2F 8y0heM4hY50IIA3fT1F+g1d0tnU9dDAs07/v8gD8hh9eQ4pot7cveVbUDJgS0GXx8hVS 7eNxG2QyI0YwKNvWtNnBix6m/stP34q8A1aOxaLa2jiL8RNaqYGcz47FOrG5r/d8NV2j gnrg== Received: by 10.60.172.236 with SMTP id bf12mr7465102oec.23.1342793632057; Fri, 20 Jul 2012 07:13:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.62.196 with HTTP; Fri, 20 Jul 2012 07:13:31 -0700 (PDT) In-Reply-To: <16160.1342792275@sss.pgh.pa.us> References: <21289.1342709554@sss.pgh.pa.us> <16160.1342792275@sss.pgh.pa.us> From: Sergey Konoplev Date: Fri, 20 Jul 2012 18:13:31 +0400 X-Google-Sender-Auth: qtEiHhQ8t4zoouOS4nr2G9Z8zIc Message-ID: Subject: Re: DELETE using an outer join To: Tom Lane Cc: Thomas Kellerer , pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201207/27 X-Sequence-Number: 36764 On Fri, Jul 20, 2012 at 5:51 PM, Tom Lane wrote: >> DELETE FROM some_table USING some_table AS s >> WHERE >> some_table.col1 = s.col1 AND >> some_table.col2 = s.col2 AND >> some_table.id < s.id; > > No, that's a self-join, which isn't what the OP wanted. You can make it > work if you self-join on the primary key and then left join to the other > table, but that's pretty klugy and inefficient. > > What was being discussed is allowing people to write directly > > DELETE FROM some_table USING some_table LEFT JOIN other_table ... > > where the respecification of the table in USING would be understood > to mean the target table. Right now this is an error case because > of duplicate table aliases. Yes, the OP has already pointed me to it. Thank you for your explanation. -- Sergey Konoplev a database architect, software developer at PostgreSQL-Consulting.com http://www.postgresql-consulting.com Jabber: gray.ru@gmail.com Skype: gray-hemp Phone: +79160686204