skip to Main Content

According to the Neo4j documentation about the WHERE clause, I should be able to filter the search using patterns with properties such as this:

SELECT *
FROM cypher('test', $$
    MATCH (n:Person)
    WHERE (n)-[:KNOWS]-({name: 'Timothy'})
    RETURN n.name, n.age
$$) AS (name agtype, age agtype);

However, I am getting an error that says:

ERROR:  syntax error at or near ":"
LINE 4: WHERE (n)-[:KNOWS]-({name: 'Timothy'})
                   ^

I’m guessing this feature has not yet been implemented in AGE but is there a way to get this to work, or is there an alternative for this to get a similar result?

2

Answers


  1. To get a similar result you can completely disregard the WHERE clause:

    SELECT * FROM cypher('test', $$
    MATCH (u)-[:KNOWS]-({name: 'Timothy'})
    RETURN u.name, u.age $$)
    AS (name agtype, age agtype);
    

    This way you will find bidirectional relationships of nodes that have the relationship KNOWS with Timothy and vice verca.

    Login or Signup to reply.
  2. Yes, you can use exists() to find whether a path with properties exists or not as

    SELECT * FROM cypher('test', $$
    MATCH (n:Person)
    WHERE exists((n)-[:KNOWS]-({name: 'Timothy'}))
    RETURN n.name, n.age
    $$) AS (name agtype, age agtype);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search