0

我有以下代码行

tx.run(CREATE n)将neo4j的螺栓库用于python。

我将收到一个存储在变量中的用户输入,我希望据此命名节点。我应该如何处理这个?谢谢

另一个例子可能是这样。我收到一个 CQL 语法错误

    if(tx.run("MATCH(n:Player{name: playername_})" "RETURN n")):
        tx.run("CREATE (playername_:Player)")
        tx.run("MATCH(username_:User)(playername_:Player)" "CREATE (playername_)-[r:IN_TEAM]->(username_)")
    else:
        tx.run("MATCH(username_:User)(playername_:Player)" "CREATE (playername_)-[r:IN_TEAM]->(username_)")

tx.run("CREATE (playername_:Player)")行引发以下错误

neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Variable `playername_` not defined (line 1, column 22 (offset: 21)) "MATCH(n:Player{name: playername_})RETURN n"

4

1 回答 1

1

我相信这可以帮助你:

playername = 'Joe'
username = 'Martin'

tx.run("CREATE (n:Player) SET n.playername = $playernamePar", playernamePar=playername)
tx.run("CREATE (n:User) SET n.username = $usernamePar", usernamePar=username)
tx.run("MATCH (p:Player),(u:User) 
        WHERE p.playername = $playernamePar 
        AND u.username = $usernamePar 
        CREATE (p)-[:inTeam]->(u)",
        playernamePar=playername, usernamePar=username)
于 2020-12-01T16:52:22.187 回答