Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6y8x-00GjFp-TF for pgsql-docs@arkaria.postgresql.org; Fri, 01 Nov 2024 20:21:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t6y8w-00HHwT-3Y for pgsql-docs@arkaria.postgresql.org; Fri, 01 Nov 2024 20:21:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6y8v-00HHwK-SP for pgsql-docs@lists.postgresql.org; Fri, 01 Nov 2024 20:21:14 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t6y8t-004F53-0j for pgsql-docs@lists.postgresql.org; Fri, 01 Nov 2024 20:21:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-ID:Content-Description; bh=zYGi4jmsjFWiUDax06NwQWFhqE9Kp3ndyeycpJ8EXoc=; b=icyomF4+c6AUyonWZAKBVVhHtu 5xdaIfrGjkBjhWscKE2xrpdQ+Fp+pIlJwgHLDBdFu6AAFTeJyGcK2uI9K/uNm0H+E+s+KWtVl1M+Y 8R9m0N+c9oeSOPe2pPu3CYAjNAb9IZWlmn+4YRQg//s0m7dLJ3LVpBjF1GNzQkjnR5gb7tNY3BaGO 5VKjONlodpeoqc5c5CjBeyjplW6h7JjytK7byqx3SWt417De5I8Kn47K/j4LadHQjgVHLHQ8sxDzY RJ337XfQGBYBaAEoWZ7T3mZMkeq+/8XEPERnTrzoEyo9xCqHp5M3Pge2YDaP3hM1HSUOncQozVffb E7cRGeaQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1t6y8r-009jp2-24; Fri, 01 Nov 2024 16:21:09 -0400 Date: Fri, 1 Nov 2024 16:21:09 -0400 From: Bruce Momjian To: "David G. Johnston" Cc: dwayne.towell@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: MERGE examples not clear Message-ID: References: <167699245721.1902146.6479762301617101634@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Sep 27, 2023 at 07:42:42PM -0400, Bruce Momjian wrote: > On Tue, Feb 21, 2023 at 08:56:50AM -0700, David G. Johnston wrote: > > On Tue, Feb 21, 2023 at 8:35 AM PG Doc comments form > > wrote: > > > > The following documentation comment has been logged on the website: > > > > Page: https://www.postgresql.org/docs/15/sql-merge.html > > Description: > > > > On this page: https://www.postgresql.org/docs/15/sql-merge.html > > the first and second examples seems to be contrasted (by "this would be > > exactly equivalent to the following statement"), however the difference > > does > > not seem to related to the stated reason ("the MATCHED result does not > > change"). It seems like the difference should involve the order of WHEN > > clauses? > > Of course, it might be that I don't understand the point, in which case > > maybe the point could be stated more clearly? > > > > > > Yeah, that is a pretty poor pair of examples.  Given that a given customer can > > reasonably be assumed to have more than one recent transaction the MERGE has a > > good chance of failing. > > > > The only difference between the two is the second one uses an explicit subquery > > as the source while the first simply names a table.  If the subquery had a > > GROUP BY customer_id that would be a good change explaining that the second > > query is different because it is resilient in the face of duplicate customer > > recent transactions. > > > > While here...source_alias (...completely hides...the fact that a query was > > issued).  What?  Probably it should read (not verified) that it is actually > > required when the source is a query (maybe tweaking the syntax to match). > > The attached patch removes the second example, which doesn't seem to add > much. Patch from September 2023 applied. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com When a patient asks the doctor, "Am I going to die?", he means "Am I going to die soon?"