Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eALMm-0005mi-E7 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Nov 2017 19:41:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eALMl-0005k5-QQ for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Nov 2017 19:41:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eALL7-0002f3-9L for pgsql-hackers@postgresql.org; Thu, 02 Nov 2017 19:39:45 +0000 Received: from sub4.mail.dreamhost.com ([69.163.253.135] helo=homiemail-a55.g.dreamhost.com) by magus.postgresql.org with esmtps (TLS1.1:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1eALL3-0000MU-QP for pgsql-hackers@postgresql.org; Thu, 02 Nov 2017 19:39:44 +0000 Received: from homiemail-a55.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a55.g.dreamhost.com (Postfix) with ESMTP id 003E068003C1B; Thu, 2 Nov 2017 12:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cryptonector.com; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=cryptonector.com; bh=jjc2AZckWqsCfI 5rsBxZ7kOCH2I=; b=lMSwcGTlkOZY33SzvlZl0uJmXaG89g81rcMf2VowAwD8Gz YnDnq71C/5XK6AAzPy5jxtMmFWjUPLXnYUqWlTU/mv3zOo0rvzkTY6F+T8SmbcP4 +7AdLSM1dR69TYXfdwTlpu8Vzep/mPbZmkUHcxaGA0FfPZa4XLwQEYd844W74= Received: from localhost (cpe-70-123-158-140.austin.res.rr.com [70.123.158.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by homiemail-a55.g.dreamhost.com (Postfix) with ESMTPSA id 87CD168003C0F; Thu, 2 Nov 2017 12:39:37 -0700 (PDT) Date: Thu, 2 Nov 2017 14:39:33 -0500 From: Nico Williams To: Simon Riggs Cc: Peter Geoghegan , Robert Haas , Michael Paquier , PostgreSQL-development Subject: Re: MERGE SQL Statement for PG11 Message-ID: <20171102193932.GS4496@localhost> References: <20171101182032.GA7104@marmot> <20171102191612.GR4496@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171102191612.GR4496@localhost> User-Agent: Mutt/1.5.24 (2015-08-30) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org If nothing else, anyone needing MERGE can port their MERGE statements to a DML with DML-containing CTEs... The generic mapping would be something like this, I think: WITH rows AS (SELECT FROM WHERE ) , updated AS ( UPDATE SET ... WHERE IN (SELECT FROM rows) /* matched */ RETURNING ) , inserted AS ( INSERT INTO SELECT ... WHERE NOT IN (SELECT FROM rows) /* not matched */ RETURNING ) DELETE FROM WHERE (...) AND NOT IN (SELECT FROM updated UNION SELECT FROM inserted); Nico -- -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers