skip to Main Content

The following code is worked well

SELECT * FROM cypher('age_graph', $$ 
    MATCH (a)-[:LocatedAt*]->(c:City)
    MATCH (a:Airport)-[e:Flight*]->(b:Airport) 
    MATCH (b)-[:LocatedAt*]->(c1:City) 
        RETURN c, a, e, b, c1
$$) AS (c agtype, airport1 agtype,e agtype , airport2 agtype, c1 agtype);

But when i want to try to return a property of edges in a path. it shows me an error like below:

SELECT * FROM cypher('age_graph', $$ 
    MATCH (a)-[:LocatedAt*]->(c:City)
    MATCH (a:Airport)-[e:Flight*]->(b:Airport) 
    MATCH (b)-[:LocatedAt*]->(c1:City) 
        RETURN c, a, e, b, c1, e.arrival_time
$$) AS (c agtype, airport1 agtype,e agtype , airport2 agtype, c1 agtype, arrival agtype);

ERROR: array index must resolve to an integer value

3

Answers


  1. Returning e.arrival_time will try to return an array consisting of all the properties of the nodes that matched in your query, thats why you get this kind of error. According to this github issue your query should look like this:

    SELECT * FROM cypher('age_graph', $$ 
        MATCH (a)-[:LocatedAt*]->(c:City)
        MATCH p = (a:Airport)-[e:Flight*]->(b:Airport) 
        MATCH (b)-[:LocatedAt*]->(c1:City)
        UNWIND (relationships(p)) AS x RETURN SUM(x.arrival_time) 
            RETURN c, a, e, b, c1, e.arrival_time
    $$) AS (c agtype, airport1 agtype,e agtype , airport2 agtype, c1 agtype, arrival agtype);
    
    Login or Signup to reply.
  2. The error message is because of that you are trying to access and array using some non-integer value as index. Lets say if value being used here as an index is not a number or if it is float value instead of integer.

    The problem is at ‘e.arrival_time’ use different expression instead of this that return an integer value . You can use id property if it is on ‘e’ relationship.

    Login or Signup to reply.
  3. You are using using VLE to match the patterns. VLE match returns an array of edges between two nodes either it contains single or muliple edges.

    In order to access properties of edges from VLE, you should either use UNWIND clause (see example 1) or you can use index (see example 2) to retrieve the edge from array and then access properties.

    Example 1

    SELECT * FROM cypher('age_graph', $$ 
        MATCH (a)-[e*]->(c) 
        UNWIND e as edge 
        RETURN properties(edge)
    $$) AS (e agtype);
    

    OR

    SELECT * FROM cypher('age_graph', $$ 
        MATCH (a)-[e*]->(c) 
        UNWIND e as edge 
        RETURN edge.distance
    $$) AS (e agtype);
    

    Example 2

    SELECT * FROM cypher('age_graph', $$ 
        MATCH (a)-[e*]->(c) 
        WITH e[0] as edge1 
        RETURN edge1.distance
    $$) AS (e agtype);
    

    Also see other questions related to VLE:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search