Re: BUG #18877: PostgreSQL triggers assertion failure

Liang, Yu <yuliang@psu.edu>

From: "Liang, Yu" <yuliang@psu.edu>
To: "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Cc: "Liang, Yu" <luy70@psu.edu>
Date: 2025-04-04T19:26:17Z
Lists: pgsql-bugs
Sorry it seems I didn’t provide the full PoC.

After launching the debug postgresql server, in psql, run the following queries.

```sql
DROP DATABASE test123;
CREATE DATABASE test123;
\c test123;
CREATE TABLE v00 (c01 INT, c02 TEXT);
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 original PoC misses the `CREATE TABLE` statement.

Best Regards,
Yu Liang

From: PG Bug reporting form <noreply@postgresql.org>
Date: Friday, April 4, 2025 at 2:49 PM
To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Cc: Liang, Yu <luy70@psu.edu>
Subject: BUG #18877: PostgreSQL triggers assertion failure
[You don't often get email from noreply@postgresql.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

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.