Skip to content

DELETE / DETACH DELETE of a collect()-list element fails with "unexpected Node for cypher_clause" #2617

Open

Description

@zihaozeng0021

DELETE / DETACH DELETE of a collect()-list element fails with "unexpected Node for cypher_clause"

Configuration

Docker Image: apache/age:release_PG18_1.8.0
Image Digest: sha256:47a0b054c3663a3e64a25fc0c5a982f1b58348019274b326a691cdf77f78eb58
PostgreSQL Version: 18.6
Apache AGE Extension Version: 1.8.0
Operating System: WSL2, Ubuntu 24.04.1 LTS
Installation Method: Docker
Query Interface: psql (SELECT * FROM cypher('xgdb', $$ ... $$) AS (...))


Description

DELETE/DETACH DELETE of a collect()-list element such as bs[0] is
accepted by the parser but aborts the statement during transformation with the internal,
should-not-happen error ERROR: unexpected Node for cypher_clause (the defensive
errmsg_internal default branch of src/backend/parser/cypher_clause.c). The failure is
independent of variable-length paths and of memory pressure: it triggers on a 2-vertex 1-edge
graph with a single-step path, before any memory is consumed.


Steps to reproduce

  1. Start the AGE container and connect with psql.
  2. Create 2 vertices and 1 edge, then run the minimal delete-of-list-element query:
SELECT create_graph('xgdb');
SELECT * FROM cypher('xgdb', $$ CREATE (:Node {id: 1})-[:R]->(:Node {id: 2}) $$) AS (r agtype);
SELECT * FROM cypher('xgdb', $$ MATCH (a:Node)-[:R]->(b:Node) WITH collect(b) AS bs LIMIT 1 DETACH DELETE bs[0] RETURN bs[0] AS first $$) AS (first agtype);
  1. For contrast, run the same pipeline without the DELETE clause
    (RETURN size(bs)); it completes normally.

Expected behaviour

The parser accepts the DELETE bs[0] expression, so a correct engine either executes the delete
or returns a clean, user-facing error (as AGE itself does for deleting a vertex that still has
edges). The issue-shaped query on the dense K10 graph should additionally not fail before any
memory pressure exists.


Actual behaviour

The statement aborts in the transform phase on both fresh-container runs:

ERROR:  unexpected Node for cypher_clause
LINE 1: SELECT * FROM cypher('xgdb', $$ MATCH (a:Node)-[:R]->(b:Node...
                                      ^

Confirmations on the same engine:

  • Non-DETACH form fails identically.
  • The same failure without LIMIT, and on the original unbounded-path issue shape on K10 and K3 -
    the error precedes any memory consumption.
  • Removing only the DELETE (RETURN size(bs)) executes normally.
  • The variants (DELETE list[0], two references in one DELETE) produce the
    same error text.

Backend process stays alive, RestartCount=0, the server log contains only the single
query-level ERROR line.


Minimal reproduction

SELECT * FROM cypher('xgdb', $$ MATCH (a:Node)-[:R]->(b:Node) WITH collect(b) AS bs LIMIT 1 DETACH DELETE bs[0] RETURN bs[0] AS first $$) AS (first agtype);

2 vertices, 1 edge; no variable-length path and no memory pressure required.


Why this appears to be a bug

The parser and the transformer disagree: a DELETE operand that the grammar accepts cannot be
transformed at all, and the failure surfaces as an internal defensive error instead of a clean
user-level message. Deleting a graph entity identified through a list element is a legitimate
Cypher operation in the reference engine, so both the rejection and the internal-error channel
are wrong.


defensive branch exists in cypher_clause.c)

Activity

  1. added
    bug
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions