public inbox for [email protected]  
help / color / mirror / Atom feed
From: PG Bug reporting form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: BUG #19463: Server crash (Assertion failure) when using MERGE statement in CTE
Date: Mon, 20 Apr 2026 09:42:33 +0000
Message-ID: <[email protected]> (raw)

The following bug has been logged on the website:

Bug reference:      19463
Logged by:          chunling qin
Email address:      [email protected]
PostgreSQL version: 15.0
Operating system:   centos
Description:        

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 = 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.








reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: BUG #19463: Server crash (Assertion failure) when using MERGE statement in CTE
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox