Existential subquery and OR in WHERE clause cause UnknownError

2020-03-14 neo4j cypher

An UnknownError occurs when I use EXISTS {...} in conjunction with OR in a WHERE clause. Is this a bug or am I missing something?

Create sample nodes

CREATE (a:A { uuid:'uuid1', foo:true })-[:KNOWS]->(b:B { uuid:'uuid2' })

Sample query

MATCH (a:A { uuid:'uuid1' }),
(b:B { uuid:'uuid2' })
WHERE a.foo = TRUE
OR EXISTS {
  MATCH (a)-[:KNOWS]->(b)
}
RETURN a

Error

Neo.DatabaseError.General.UnknownError
There should be at least one pattern expression

Answers

As @InverseFalcon indicates, this does seem like a bug (or at least an undocumented existential subquery limitation).

As a workaround, since your subquery has no WHERE clause, you can just use the EXISTS function:

MATCH (a:A {uuid: 'uuid1'}), (b:B {uuid: 'uuid2'})
WHERE a.foo OR EXISTS((a)-[:KNOWS]->(b))
RETURN a

This was indeed a bug/oversight in Neo4j's existential subquery implementation. I have now implemented a fix which will be included in a upcoming 4.0 release. Thanks for reporting!

Best regards Louise, Neo4j Cypher team

Related