apoc.cypher.runFirstColumnMany
语法 |
|
||
描述 |
使用给定参数运行给定语句,并将第一列收集到一个 |
||
参数 |
名称 |
类型 |
描述 |
|
|
要执行的 Cypher 查询。 |
|
|
|
给定 Cypher 查询所需的输入参数。 |
|
返回 |
|
||
|
此函数不被认为是线程安全的,因此并行运行时不支持它。更多信息请参阅 Cypher 手册 → 并行运行时。 |
在 Cypher 中使用动态标签
节点标签和关系类型可以在 Cypher 中动态引用,无需使用 APOC。
动态创建、匹配和合并标签和类型的 Cypher 语法
CREATE (n1:$(label))-[r:$(type)]->(n2:$(label))
MERGE (n1:$(label))-[r:$(type)]->(n2:$(label))
MATCH (n1:$(label))-[r:$(type)]->(n2:$(label))
动态计算的类型必须评估为 STRING 或 LIST<STRING>。更多信息请参阅 Cypher 手册 → CREATE、MERGE、MATCH。
使用示例
本节中的示例基于以下示例图
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (TomH:Person {name:'Tom Hanks', born:1956})
CREATE (TomT:Person {name:'Tom Tykwer', born:1965})
CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})
CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})
CREATE (SomethingsGottaGive:Movie {title:"Something's Gotta Give", released:2003})
CREATE (TheDevilsAdvocate:Movie {title:"The Devil's Advocate", released:1997, tagline:'Evil has its winning ways'})
CREATE (YouveGotMail:Movie {title:"You've Got Mail", released:1998, tagline:'At odds in life... in love on-line.'})
CREATE (SleeplessInSeattle:Movie {title:'Sleepless in Seattle', released:1993, tagline:'What if someone you never met, someone you never saw, someone you never knew was the only someone for you?'})
CREATE (ThatThingYouDo:Movie {title:'That Thing You Do', released:1996, tagline:'In every life there comes a time when that thing you dream becomes that thing you do'})
CREATE (CloudAtlas:Movie {title:'Cloud Atlas', released:2012, tagline:'Everything is connected'})
CREATE (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix)
CREATE (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixReloaded)
CREATE (Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixRevolutions)
CREATE (Keanu)-[:ACTED_IN {roles:['Julian Mercer']}]->(SomethingsGottaGive)
CREATE (Keanu)-[:ACTED_IN {roles:['Kevin Lomax']}]->(TheDevilsAdvocate)
CREATE (TomH)-[:ACTED_IN {roles:['Joe Fox']}]->(YouveGotMail)
CREATE (TomH)-[:ACTED_IN {roles:['Sam Baldwin']}]->(SleeplessInSeattle)
CREATE (TomH)-[:ACTED_IN {roles:['Mr. White']}]->(ThatThingYouDo)
CREATE (TomH)-[:ACTED_IN {roles:['Zachry', 'Dr. Henry Goose', 'Isaac Sachs', 'Dermot Hoggins']}]->(CloudAtlas)
CREATE (TomT)-[:DIRECTED]->(CloudAtlas);
此函数可用于执行具有动态节点标签或关系类型并返回多行单列的 Cypher 语句。但是,这也可以在不使用 APOC 的情况下实现(如果可能,以下示例将展示 Cypher 和 APOC 两种替代方案)。
例如,我们可以返回所有标签的列表,以及带有这些标签的节点使用的不同属性键集。
apoc.cypher.runFirstColumnMany
CALL db.labels()
YIELD label
RETURN label,
apoc.cypher.runFirstColumnMany(
"MATCH (n:`" + label + "`)
WITH DISTINCT keys(n) AS keys
RETURN DISTINCT apoc.coll.sort(keys)",
{}) AS keys;
MATCH 子句
CALL db.labels()
YIELD label
RETURN label, COLLECT {
MATCH (n:$(label))
WITH DISTINCT keys(n) AS keys
RETURN DISTINCT apoc.coll.sort(keys)
};
| 标签 | 键 |
|---|---|
"Person" |
[["born", "name"]] |
"Movie" |
[["released", "tagline", "title"], ["released", "title"]] |