Silence6666668 opened a new issue, #2388:
URL: https://github.com/apache/age/issues/2388

   **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:
   
   ```text
   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?**
   ```pgsql
   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?**
   ```pgsql
   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:
   ```text
   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:
   ```text
   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:
   
   ```pgsql
   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.
   
   2. Sorting by a scalar alias also works:
   
   ```pgsql
   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:
   ```text
   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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to