Skip to content

ORDER BY may fail on Apache AGE when it references a property of a node value returned under an alias. #2388

@Silence6666668

Description

@Silence6666668

Describe the bug
ORDER BY may fail on Apache AGE when it references a property of a node value returned under an alias.

In the minimized repro below, the query returns n AS person and then sorts by person.name. Neo4j and Memgraph both accept this and return the expected rows.

Instead, AGE fails with:

could not find rte for person

and reports that person is out of scope.

How are you accessing AGE (Command line, driver, etc.)?

  • PostgreSQL cypher(...) wrapper through the local Python differential-testing harness
  • Reproducible directly in psql inside the Docker container

What data setup do we need to do?

SELECT * FROM cypher('fuzz_graph', $$
  CREATE (:Person {name: 'Alice'}),
         (:Person {name: 'Bob'}),
         (:Person {name: 'Charlie'})
$$) AS (v agtype);

What is the necessary configuration info needed?

  • Plain Apache AGE Docker image was enough
  • Docker image in local repro: apache/age
  • AGE extension version: 1.7.0
  • PostgreSQL version: 18.1
  • Graph name used in repro: fuzz_graph
  • No extra extensions or special configuration were required

What is the command that caused the error?

SELECT * FROM cypher('fuzz_graph', $$
  MATCH (n:Person)
  RETURN n AS person
  ORDER BY person.name DESC
  LIMIT 2
$$) AS (person agtype);

Returned result on AGE:

ERROR:  could not find rte for person
HINT:  variable person does not exist within scope of usage

Expected behavior
The query should succeed and return the two lexicographically largest Person nodes by name.

Observed behavior on Neo4j and Memgraph:

Charlie
Bob

Environment (please complete the following information):

  • Version: Apache AGE 1.7.0
  • PostgreSQL: 18.1
  • Host OS: Windows
  • Architecture: x86_64
  • Deployment: Docker

Additional context
Two nearby control cases behave correctly on the same AGE instance:

  1. Sorting by the original variable instead of the return alias:
SELECT * FROM cypher('fuzz_graph', $$
  MATCH (n:Person)
  RETURN n AS person
  ORDER BY n.name DESC
  LIMIT 2
$$) AS (person agtype);

AGE returns the expected two rows there.

  1. Sorting by a scalar alias also works:
SELECT * FROM cypher('fuzz_graph', $$
  MATCH (n:Person)
  RETURN n.name AS person
  ORDER BY person DESC
  LIMIT 2
$$) AS (person agtype);

AGE also returns:

Charlie
Bob

So the issue appears specific to property access through a return alias that holds a node value, rather than to ORDER BY aliases in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions