[英]Neo4j Cypher boolean condition and IN
在繼續我的上一個問題Neo4j Cypher查詢為null或IN時,我已將isPublic
屬性添加到Tenant
節點。
現在我需要延長善意所創建的查詢frant.hartm與額外的檢查parentD
和childD
租戶isPublic
條件。
我的發言擴展到以下內容:
t.isPublic OR t in tenants WHERE (parentD)-[:BELONGS_TO]-(t)
但失敗,但以下異常:
org.neo4j.ogm.exception.CypherException: Error executing Cypher; Code: Neo.ClientError.Statement.SyntaxError; Description: Invalid input 'W': expected whitespace, comment, '{', node labels, MapLiteral, a parameter, a relationship pattern, '(', '.', '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ')' (line 1, column 254 (offset: 253))
"MATCH (t:Tenant) WHERE ID(t) in {tenantIds} WITH COLLECT(t) as tenants MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} AND (not(parentD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (parentD)-[:BELONGS_TO]-(t))) AND (not (childD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (childD)-[:BELONGS_TO]-(t))) RETURN ru, u, childD ORDER BY childD.createDate ASC SKIP 0 LIMIT 100"
^
at org.neo4j.ogm.drivers.embedded.request.EmbeddedRequest.executeRequest(EmbeddedRequest.java:175)
at org.neo4j.ogm.drivers.embedded.request.EmbeddedRequest.execute(EmbeddedRequest.java:66)
現在的完整查詢如下所示:
MATCH (t:Tenant) WHERE ID(t) in {tenantIds}
WITH COLLECT(t) as tenants
MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User)
WHERE
id(parentD) = {decisionId}
AND
(not(parentD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (parentD)-[:BELONGS_TO]-(t)))
AND
(not (childD)-[:BELONGS_TO]-(:Tenant) OR any(t.isPublic OR t in tenants WHERE (childD)-[:BELONGS_TO]-(t)))
RETURN ru, u, childD
ORDER BY childD.createDate ASC
SKIP 0 LIMIT 100
如何修復此查詢以支持t.isPublic
?
任何運算符的語法如下:
any(variable IN list WHERE predicate)
參見: https : //neo4j.com/docs/developer-manual/current/cypher/functions/predicates/#functions-any
您將t.isPublic
放到錯誤的位置,在該上下文中未定義t,需要將其放在內部WHERE子句之后:
any(t in tenants WHERE t.isPublic OR (parentD)-[:BELONGS_TO]-(t))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.