What does separate curly bracket means in Cypher?

huangapple go评论77阅读模式
英文:

What does separate curly bracket means in Cypher?

问题

我已阅读文档,并发现花括号通常用于形成子查询,或者用于描述节点或关系的属性。

但我注意到有时花括号被单独使用,我不明白它究竟在做什么。

以下是一些单独使用花括号的示例:

  1. MATCH (p:Person)
  2. RETURN
  3. p,
  4. p.name AS name,
  5. toUpper(p.name),
  6. coalesce(p.nickname, 'n/a') AS nickname,
  7. {name: p.name, label: head(labels(p))} AS person // 这句话在做什么?
  1. MATCH (e:Entity)-[r1:{}]-(t1:Entity)
  2. WHERE e.lid IN {{qids}} AND e.name <> ""
  3. WITH e, r1, t1
  4. OPTIONAL MATCH (t1)-[r2]-(t2:Entity)
  5. WHERE t1.name = ""
  6. AND t2.name <> ""
  7. AND t2 <> e
  8. WITH e, r1, t1, r2, t2
  9. WHERE t1.name <> "" OR (t2 IS NOT NULL AND t2.name <> "")
  10. RETURN e,
  11. { name : r1.name, labelId: r1.labelId, type: type(r1) } as r1, // 这个
  12. t1,
  13. { name : r2.name, labelId: r2.labelId, type: type(r2) } as r2, // 和这个
  14. t2
  15. ORDER BY t2.score IS NOT NULL DESC, t1.score IS NOT NULL DESC,
  16. t2.score DESC, t1.score DESC
  17. LIMIT 20

提前致以诚挚的感谢!

英文:

I have read the document, and i found that curly brackets are normally used to form a subquery or it can be used to describe the properties of a node or relationships.

But i notice that some times curly brackets are used separately, and i can't understand what exactly it was doing.

Here are some example of curly brackets used separately:

  1. MATCH (p:Person)
  2. RETURN
  3. p,
  4. p.name AS name,
  5. toUpper(p.name),
  6. coalesce(p.nickname, &#39;n/a&#39;) AS nickname,
  7. {name: p.name, label: head(labels(p))} AS person // what is this sentence doing?
  1. MATCH (e:Entity)-[r1:{}]-(t1:Entity)
  2. WHERE e.lid IN {{qids}} AND e.name &lt;&gt; &quot;&quot;
  3. WITH e, r1, t1
  4. OPTIONAL MATCH (t1)-[r2]-(t2:Entity)
  5. WHERE t1.name = &quot;&quot;
  6. AND t2.name &lt;&gt; &quot;&quot;
  7. AND t2 &lt;&gt; e
  8. WITH e, r1, t1, r2, t2
  9. WHERE t1.name &lt;&gt; &quot;&quot; OR (t2 IS NOT NULL AND t2.name &lt;&gt; &quot;&quot;)
  10. RETURN e,
  11. { name : r1.name, labelId: r1.labelId, type: type(r1) } as r1, // this
  12. t1,
  13. { name : r2.name, labelId: r2.labelId, type: type(r2) } as r2, // and this
  14. t2
  15. ORDER BY t2.score IS NOT NULL DESC, t1.score IS NOT NULL DESC,
  16. t2.score DESC, t1.score DESC
  17. LIMIT 20

many thanks in advance!

答案1

得分: 1

你正在创建一个键值对的映射。类似于

  1. { name: "Some-name", labelId: "some-value" ... }
英文:

You are essentially creating a map of key value pairs. Along the lines of

  1. { name: &quot;Some-name&quot;, labelId: &quot;some-value&quot; ... }

答案2

得分: 0

Kevin的答案是正确的。

在这里,您正在定义一个名为Person的节点。键-值对用于定义所讨论节点的属性。

  1. MATCH (p:Person)
  2. RETURN
  3. p,
  4. p.name AS name,
  5. toUpper(p.name),
  6. coalesce(p.nickname, 'n/a') AS nickname,
  7. {name: p.name, label: head(labels(p))} AS person
  1. {name: p.name, label: head(labels(p))}

在这里,您正在定义{key1: value1, key2: value2}。

这是在大多数编程语言中表示从接口定义对象的方式。

英文:

Kevin's answer is correct.

You are defining a node here Person. The Key-value pair is to define the properties of the node in question.

  1. MATCH (p:Person)
  2. RETURN
  3. p,
  4. p.name AS name,
  5. toUpper(p.name),
  6. coalesce(p.nickname, &#39;n/a&#39;) AS nickname,
  7. {name: p.name, label: head(labels(p))} AS person
  1. {name: p.name, label: head(labels(p))}

Here, you're defining {key1: value1, key2: value2}.

This is a representation of what would be considered defining an object from an interface in most programming languages.

huangapple
  • 本文由 发表于 2023年1月9日 09:00:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75052365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定