I've tried a bunch of cypher queries, most coming from this question, but none worked.
E.g.:
postgres=# match (a)<-[r]-() where r is null return *;
a | r
---+---
(0 rows)
The last one I tried is this:
match (n) where not (n)<-[]-() return *
obtaining a syntax error:
postgres=# match (n) where not (n)<-[]-() return *;
ERROR: syntax error at or near ")"
LINE 1: match (n) where not (n)<-[]-() return *;
I finally fired up Neo4j and found that the above mentioned cypher query works there.
What's the equivalent in AgensGraph (2.1.3) Cypher?
While waiting for the correct solution, I worked around the issue with the following sequence of queries:
match (a)<-[]-(b) SET b.child=true;
match(a) where a.child is null return a;
match(a) where a.child is not null remove a.child;
Eventually wrapped within a transaction so not to alter the graph properties.
You're query match (n) where not (n)<-[]-() return *;
is close however you need to add 2 more elements to get the query to work.
So I ran this query: MATCH (a) WHERE NOT EXISTS ((a)<-[]-()) RETURN *;
and it worked.