BUG #18877: PostgreSQL triggers assertion failure

PG Bug reporting form <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: luy70@psu.edu
Date: 2025-04-04T18:48:21Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18877
Logged by:          Yu Liang
Email address:      luy70@psu.edu
PostgreSQL version: 17.4
Operating system:   Ubuntu 24.04 LTS ARM64 VM
Description:        

In the debug build of PostgreSQL 17.4, compiled with `configure
--enable-debug --prefix=$(pwd) --exec-prefix=$(pwd) --enable-cassert`,
triggered Assertion Failure when executing the following statement: 

```sql
SELECT ALL GROUP BY ALL ( ), CUBE ( CASE WHEN FALSE THEN TRUE END )
INTERSECT ALL SELECT ALL FROM JSON_ARRAY ( WITH any_cte_name AS ( ( TABLE
v00 ) ) VALUES ( FALSE ) ), any_table_name GROUP BY CUBE ( CASE WHEN TRUE
THEN FALSE END );
```

The assertion triggered is: Assert("IsA(cte->ctequery, InsertStmt) ||
IsA(cte->ctequery, UpdateStmt) || IsA(cte->ctequery, DeleteStmt) ||
IsA(cte->ctequery, MergeStmt)"). 
File: "/home/postgresql/postgres/bld/../src/backend/parser/parse_cte.c",
Line: 150.

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Avoid double transformation of json_array()'s subquery.