apache-ageopencypher

Express abscence of edges in OpenCypher


This question has an answer for how to find nodes which don't have outgoing edges on neo4j and cypher:

MATCH ()-[:A]->(n) WHERE NOT (n)-->() RETURN n

However, this does not work on Apache AGE:

select *
from cypher('graph_name', $$
    MATCH ()-[:A]->(n) WHERE NOT (n)-->() RETURN n
$$) as (n agtype)

which gives:

ERROR:  syntax error at or near ">"
LINE 3:  MATCH ()-[:A]->(n) WHERE NOT (n)-->() RETURN n
                                           ^ 

SQL state: 42601
Character: 69

How can I accomplish the same query in Apache AGE?

I'm using the latest version of Apache AGE (1.5.0) at time of posting.

I've tried variations for the NOT clause such as

but none have worked.


Solution

  • The equivalent query is:

    select *
    from cypher('graph_name', $$
        match ()-[:A]->(n)
        where not exists((n)-[]->())
        return distinct n
    $$) as (n agtype)
    

    The difference is that this part of the query:

    WHERE NOT (n)-->()
    RETURN n
    

    is replaced with:

    WHERE NOT EXISTS((n)-[]->())
    RETURN DISTINCT n