Skip to content

Cypher: a RETURN alias matching a pattern variable silently replaces the projection, and can drop every row #1857

Closed

Description

@aaj3f

An openCypher RETURN alias that happens to match a pattern variable silently changes what the projection returns — in one case dropping every row. Nothing warns, and the wrong answers are plausible enough to be taken at face value.

Repro

Any ledger with an annotated edge; this uses two claims on ex:alice ex:knows ex:bob.

$ fluree query -l v:main --cypher -e \
    'MATCH (a)-[r:`http://example.org/knows`]->(b) RETURN a.`@id` AS aid LIMIT 2'
  → [null, null]

$ fluree query -l v:main --cypher -e \
    'MATCH (a)-[r:`http://example.org/knows`]->(b) RETURN a.`@id` AS a LIMIT 2'
  → ["http://example.org/alice", "http://example.org/alice"]

$ fluree query -l v:main --cypher -e \
    'MATCH (a)-[r:`http://example.org/knows`]->(b) RETURN r.`…/confidence` AS conf LIMIT 2'
  → ["0.8", "0.9"]

$ fluree query -l v:main --cypher -e \
    'MATCH (a)-[r:`http://example.org/knows`]->(b) RETURN r.`…/confidence` AS r LIMIT 2'
  → []            ← every row dropped

Same pattern, same projection expression, three different outcomes depending only on the alias.

What seems to be happening

When the alias collides with a bound pattern variable, the projection expression appears to be discarded in favour of the variable itself. For a node variable that yields the node (rendered as its IRI); for a relationship variable it yields nothing at all and the row count goes to zero.

The AS r case is the one that worries me most. A user writing RETURN r.confidence AS r — which reads naturally — gets an empty result with no error, no warning, and no indication that the alias is the cause. The AS a case is subtler still: it returns something, and something that looks like a reasonable answer, so it can be consumed without anyone noticing the projection never ran.

Separately: n. + @id is not a readable property

Worth deciding at the same time, since it is how people find the above. a.@id returns `null` (first repro line); the accessor that works is `id(a)`. That is defensible openCypher — reading an absent property yields `null` — but in an RDF-backed store where `@id` *is* the node's identity, and where every other query surface spells it `@id`, reaching for `n.`@id is close to the first thing someone will try. Either making it resolve, or rejecting it with a message naming id(n), would save that discovery.

Suggested direction

At minimum, aliasing a projection to an already-bound variable should be an error naming the collision, rather than silently resolving to the variable. If there is a reason to allow the shadowing, the projection expression should still be what is evaluated.

Environment

main @ 3d89e8f, release build, macOS. Also reproduces on v4.2.0 (RETURN r.conf AS r -> []), so this is not a recent regression.

Activity

  1. added
    bug
    P1
    area:query
    on Sep 16, 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

    P1area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions