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 1trecm-006peD-9o for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Mar 2025 15:01:00 +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 1trecl-00DOkX-0Z for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Mar 2025 15:00:59 +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 1treck-00DOkP-Nf for pgsql-bugs@lists.postgresql.org; Mon, 10 Mar 2025 15:00:58 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1trecg-0023cd-37 for pgsql-bugs@lists.postgresql.org; Mon, 10 Mar 2025 15:00:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 52AF0kQI765995; Mon, 10 Mar 2025 11:00:46 -0400 From: Tom Lane To: Tender Wang cc: Dean Rasheed , Duncan Sands , pgsql-bugs@lists.postgresql.org Subject: Re: Attribute of type record has wrong type error with MERGE ... WHEN NOT MATCHED BY SOURCE THEN DELETE In-reply-to: References: <3518c50a-ab18-482f-b916-a37263622501@deepbluecap.com> Comments: In-reply-to Tender Wang message dated "Mon, 10 Mar 2025 21:46:36 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <765993.1741618846.1@sss.pgh.pa.us> Date: Mon, 10 Mar 2025 11:00:46 -0400 Message-ID: <765994.1741618846@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tender Wang writes: > When the query has NOT MATCHED BY SOURCE, commit d7d297f84 add "src IS NOT > NULL" join condition. > In this case, the src is view(e.g. subquery), so in makeWholeRowVar(), it > will call below code: > result = makeVar(varno, > InvalidAttrNumber, > RECORDOID, > -1, > InvalidOid, > varlevelsup); > the vartype is RECORDOID, but te reltype of src is not RECORDOID, so > $SUBJECT error reports. Hmm. I tried adjusting the example to make _country_or_region be a materialized view or plain table instead of a view, and those cases did not fail. I wonder why the difference... > I add the below codes to makeWholeRowVar() default branch: > if (rte->relkind == RELKIND_VIEW) > toid = get_rel_type_id(rte->relid); > else > toid = RECORDOID; > It can work. I'm quite uncomfortable with the idea of changing makeWholeRowVar() itself in this way --- the potential blast radius from that seems rather large. A localized fix in transform_MERGE_to_join() might be a wiser answer. regards, tom lane