neo4j cypher py2neo len统计run函数返回的data的个数为0

错误:

query = "MATCH p=(p3:战争{name:'"+select1+"'})-[r1:`战役`]->(p1:战役)-[r2]->(h)<-[r3]-(p2:战役)<-[r4:`战役`]-(p4:战争{name:'"+select2+"'}) RETURN distinct(p1)"
result = graph.run(query)
print((result.data()))
print('len', len(result.data()))

正确:

query = "MATCH p=(p3:战争{name:'"+select1+"'})-[r1:`战役`]->(p1:战役)-[r2]->(h)<-[r3]-(p2:战役)<-[r4:`战役`]-(p4:战争{name:'"+select2+"'}) RETURN distinct(p1)"
result = graph.run(query).data()
print((result))
print('len', len(result))

.data() 必须要和graph一起

官方例子

data()

Consume and extract the entire result as a list of dictionaries.

 from py2neo import Graph
 graph = Graph()
graph.run("MATCH (a:Person) RETURN a.name, a.born LIMIT 4").data()
[{
     'a.born': 1964, 'a.name': 'Keanu Reeves'},
 {
     'a.born': 1967, 'a.name': 'Carrie-Anne Moss'},
 {
     'a.born': 1961, 'a.name': 'Laurence Fishburne'},
 {
     'a.born': 1960, 'a.name': 'Hugo Weaving'}]
 

Returns :the full query result
Return type:list of dict

参考资料

https://py2neo.org/v4/database.html?highlight=run#py2neo.database.Cursor

你可能感兴趣的:(neo4j,neo4j)