我正在执行一项操作,我需要根据某些要求进行操作,查询是::
MATCH (n:Label1)
OPTIONAL MATCH (n)-[:REL_1]-(e:Label2)
WITH n,e,
CASE
WHEN e IS NULL THEN
MERGE (ss:Label2{sId:n.id})
ON MATCH SET ss.id = 1476988200, ss.setC = ss.setC +1,ss.nl = ss.nl + [4]
ON CREATE SET ss.id = 1476988200, ss.setC = 1,ss.nl = [6]
CREATE UNIQUE (n)-[:REL_1]->(ss)
WHEN e.id<1476988200 THEN
MERGE (ss:Label2 {sId: n.id})
ON MATCH SET ss.id = 1476988200, ss.setC = ss.setC +1,ss.nl = ss.nl + [4]
ON CREATE SET ss.id = 1476988200, ss.setC = 1,ss.nl = [6]
CREATE UNIQUE (n)-[:REL_1]->(ss)
WHEN e.id=1476988200 AND e.setC < 3 THEN
MERGE (ss:Label2 {sId: n.id})
ON MATCH SET ss.id = 1476988200, ss.setC = ss.setC +1,ss.nl = ss.nl + [4]
ON CREATE SET ss.id = 1476988200, ss.setC = 1,ss.nl = [6]
CREATE UNIQUE (n)-[:REL_1]->(ss)
END
虽然我在这里添加了相同的案例;每种情况都有不同的情景。
(因为我无法解释问题,我写了这个::对不起)
但是我收到了像::
这样的错误Invalid input ')': expected whitespace or a relationship pattern (line 6, column 36 (offset: 138))
要实现这个::我试过这样(但仍然产生错误)::
MATCH (n:Label1)
OPTIONAL MATCH (n)-[:REL_1]-(e:Label2)
WITH n,e
WHERE e IS NULL OR e.id<1476988200 OR (e.id=1476988200 AND e.setC < 3)
WITH collect(n) as total_rows
FOREACH (i IN RANGE(0, size(total_rows)-1) |
FOREACH (sub IN [total_rows[i]] |
MERGE (ss:Label2 {sId: sub.id})
ON CREATE SET ss.id = 1476988200, ss.setC = 1 AND ss.nl = [6]
ON MATCH SET CASE WHEN ss.id = 1476988200 THEN (ss.setC = ss.setC +1 AND ss.nl = ss.nl + [4]) WHEN ss.id< 1476988200 THEN (ss.id = 1476988200 AND ss.setC = 0 AND ss.nl = []) END
CREATE UNIQUE (sub)-[:REL_1]->(ss)
)
)
错误:: Invalid input 'C': expected whitespace, comment or '.' (line 11, column 3 (offset: 553))
有什么问题?或者还有其他方法可以解决这个问题。
答案 0 :(得分:0)
问题在于CASE
仅选择要评估的表达式来代替另一个表达式;内部不允许MATCH
,CREATE
等。对于这样的查询,您要做的基本上是创建行列表,将该列表过滤为特定类型的行的三个单独列表,然后UNWIND
并分别处理每个列表。更新:潜在空列表的解决方法很复杂,因此最简单的方法是使用三个单独的查询UNION ALL
。
MATCH (n:Label1)
WHERE NOT (n)-[:REL_1]-(:Label2)
MERGE (ss:Label2 {sId: n.id})
ON MATCH SET ss.id = 1476988200, ss.setC = ss.setC +1,ss.nl = ss.nl + [4]
ON CREATE SET ss.id = 1476988200, ss.setC = 1,ss.nl = [6]
CREATE UNIQUE (n)-[:REL_1]->(ss)
RETURN 'null_rows' AS type, COUNT(*) AS num
UNION ALL
MATCH (n:Label1)-[:REL_1]-(e:Label2)
WHERE e.id < 1476988200
MERGE (ss:Label2 {sId: n.id})
ON MATCH SET ss.id = 1476988200, ss.setC = ss.setC +1,ss.nl = ss.nl + [4]
ON CREATE SET ss.id = 1476988200, ss.setC = 1,ss.nl = [6]
CREATE UNIQUE (n)-[:REL_1]->(ss)
RETURN 'less_than_rows' AS type, COUNT(*) AS num
UNION ALL
MATCH (n:Label1)-[:REL_1]-(e:Label2)
WHERE e.id = 1476988200 AND e.setC < 3
MERGE (ss:Label2 {sId: n.id})
ON MATCH SET ss.id = 1476988200, ss.setC = ss.setC +1,ss.nl = ss.nl + [4]
ON CREATE SET ss.id = 1476988200, ss.setC = 1,ss.nl = [6]
CREATE UNIQUE (n)-[:REL_1]->(ss)
RETURN 'other_rows' AS type, COUNT(*) AS num