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 1stxB7-002ybN-G6 for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Sep 2024 22:41:42 +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 1stxB4-00FVSK-Ry for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Sep 2024 22:41:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stxB4-00FVSC-Jb for pgsql-bugs@lists.postgresql.org; Thu, 26 Sep 2024 22:41:38 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1stxB2-001DwC-8o for pgsql-bugs@lists.postgresql.org; Thu, 26 Sep 2024 22:41:37 +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 48QMfT4d374421; Thu, 26 Sep 2024 18:41:29 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18634: Wrong varnullingrels with merge ... when not matched by source In-reply-to: <18634-db5299c937877f2b@postgresql.org> References: <18634-db5299c937877f2b@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 26 Sep 2024 18:00:01 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <374419.1727390489.1@sss.pgh.pa.us> Date: Thu, 26 Sep 2024 18:41:29 -0400 Message-ID: <374420.1727390489@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > The following script: > CREATE TABLE t (a int); > INSERT INTO t VALUES(1), (2); > CREATE VIEW v AS SELECT a FROM t WHERE EXISTS (SELECT 1 FROM t); > MERGE INTO v USING (SELECT * FROM generate_series(1,1)) AS s(a) > ON s.a = v.a WHEN NOT MATCHED BY SOURCE THEN DELETE; > produces: > ERROR: XX000: wrong varnullingrels (b) (expected (b 4)) for Var 5/1 > LOCATION: search_indexed_tlist_for_var, setrefs.c:2847 I haven't run this fully to ground, but what it looks like is that preprocess_targetlist is generating row identity Vars that lack required varnullingrels. I don't understand though why this only seems to affect MERGE. regards, tom lane