neo4j
neo4j copied to clipboard
Unexpected Exeception when Using "%" Label in the Variable-length Relationship
- Neo4j version: 5.8.0-enterprise
- Operating system: Ubuntu 20.04
- API/Driver: Cypher
- Steps to reproduce
Hello! While testing Neo4j, I met an unexpected exception when using the %
label in the variable length relationship.
In practice, when executing the following query, an exception was raised.
MATCH (A)<-[:(%)*1..2]-(B) RETURN *
=> Neo.ClientError.Statement.SyntaxError
The detailed information is Variable length relationships must not use relationship type expressions. (line 1, column 16 (offset: 15))
I believe it may indicate a potential bug of Neo4j because the following two queries are OK to execute.
MATCH (A)<-[:%]-(B) RETURN *
MATCH (A)<-[:(KNOWS)*1..2]-(B) RETURN *
Would it is possible for you to further confirm and investigate this issue?
Hello @joyemang33 and thanks for your report.
The %
token has a special meaning - it matches any label/relationship type. See the documentation.
Label expressions were introduced in version 5.0, but with some gaps in which places they are not allowed (yet). We are aware of this restriction and might lift it in the future.
For now, you can simply remove the %
, since all relationships must have a type, so the predicate does not achieve anything in this query. For other relationship type expressions, you can use the new feature quantified path pattern, which allows you to express the same as with a variable-length relationship and more. Quantified path pattern allow relationship type expressions to be used.
Hi @sherfert ! Thanks for your explanation!
However, I think the exception here may make some confusion because other label expression excluding '%' associated with the relationship with variable length is OK to execute, such as 'A|B'. Would you confirm it as an issue and make such exceptions more consistent?
@joyemang33
You are right, things are for from consistent.
The only explanation that I can offer is that |
has been supported for a long time, while %
was added in 5.0.
This is explicitly documented here: "Type expressions are limited to the disjunction operator."
We already track this inconsistency in our issue tracker and I will attach this github issue to it and reopen it. However, I believe that this will get lower priority compared to adding more functionality to the new quantified path patterns.
@sherfert Many thanks for your help, and I totally agree with you that adding more functionality to the new quantified path pattern is more important!
Maybe a good and simple solution for this inconsistency is slightly edit the content of the exception.
Looking forward to the new functionality and the improvement of the inconsistency.
Hi @sherfert ! I also noticed that !
also has not been supported in such cases. Hope the additional information can help you!