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.96) (envelope-from ) id 1wEpIw-004S8y-24 for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 14:08:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEpIv-003Eqe-2z for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Apr 2026 14:08:49 +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.96) (envelope-from ) id 1wEl9p-001rm2-1O for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 09:43:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wEl9m-000000026w5-2QUZ for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 09:43:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=V9n51gl7AwbfehyU0xJ3wVGEMn6UAtfUCU5+6iVcjcg=; b=hIE4SZwzH6AdWj2xtWthKrZh9V 8PCoJBO2UmHiIbyB8CtFkNHJdL2NrVhBNzJOwIiRILQfgvaHcK16g2WynVs4G8vgBW4dfVxyrJI0f Ci5sj+CaQt6ggJgV0CDFr62S4XqMrngRT3eUuFPFbPZLombJntyIdURZMeB7kGnCdjF6eI0GuL7/a WD1Jp3Z50gue999zd5B1PMjOC6LIpHgfNU/aP3h+HiLl7Yi7ZOV9tXahJ/IXzXKMo4xb8mw3hrmbR NfoEYjSsVIugyVBEQWJAtSD8ngYZYnUQQC9IrRl0faoBszMD6HyONlgeqIKIrpgLFYl3+K5siC12j IancV/SA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wEl9k-005fDM-0v for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 09:43:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wEl9i-00Cfjz-2X for pgsql-bugs@lists.postgresql.org; Mon, 20 Apr 2026 09:43:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19463: Server crash (Assertion failure) when using MERGE statement in CTE To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 303677365@qq.com Reply-To: 303677365@qq.com, pgsql-bugs@lists.postgresql.org Date: Mon, 20 Apr 2026 09:42:33 +0000 Message-ID: <19463-f59d5d2a41969756@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19463 Logged by: chunling qin Email address: 303677365@qq.com PostgreSQL version: 15.0 Operating system: centos Description: =20 Using a MERGE statement as a Common Table Expression (CTE) causes the PostgreSQL server to crash with an assertion failure. The assertion in `transformWithClause` does not recognize `MergeStmt` as a valid data-modifying statement type. ## PostgreSQL Version ``` PostgreSQL 15devel on x86_64-pc-linux-gnu, compiled by clang version 17.0.6, 64-bit ``` Tested on REL_15_STABLE branch. ## Steps to Reproduce ```sql -- Setup CREATE TABLE target (col_int INT, col_varchar VARCHAR(2000)); CREATE TABLE source (col_int INT, col_varchar VARCHAR(2000)); INSERT INTO source VALUES (1, 'test'); -- This query causes server crash WITH merge_cte AS ( MERGE INTO target t USING source s ON t.col_int =3D s.col_int WHEN NOT MATCHED THEN INSERT (col_int, col_varchar) VALUES (s.col_int, s.col_varchar) ) SELECT col_int FROM merge_cte; ``` ## Actual Behavior ``` server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. connection to server was lost ``` The server crashes with SIGABRT due to a failed assertion. ## Stack Trace ``` #0 0x00007fb27809d294 __pthread_kill_implementation (libc.so.6 + 0x91294) #1 0x00007fb27804aaf6 raise (libc.so.6 + 0x3eaf6) #2 0x00007fb278032897 abort (libc.so.6 + 0x26897) #3 0x00005571eb6e064a ExceptionalCondition (postgres + 0xb3364a) #4 0x00005571eae8f452 transformWithClause (postgres + 0x2e2452) #5 0x00005571eae20ca1 transformSelectStmt (postgres + 0x273ca1) #6 0x00005571eae1dd49 transformStmt (postgres + 0x270d49) #7 0x00005571eae1e14c transformOptionalSelectInto (postgres + 0x27114c) #8 0x00005571eae1d713 transformTopLevelStmt (postgres + 0x270713) #9 0x00005571eae1d647 parse_analyze_fixedparams (postgres + 0x270647) #10 0x00005571eb415471 pg_analyze_and_rewrite_fixedparams (postgres + 0x868471) #11 0x00005571eb41a3db exec_simple_query (postgres + 0x86d3db) #12 0x00005571eb419312 PostgresMain (postgres + 0x86c312) ``` This issue could not be reproduced with the latest version, but we can easily reproduced by PostgreSQL 15devel. I am submitting this report for official confirmation.