Reputation: 1115
I am copying code directly from neo4j's Cypher manual, but the code does not work in my environment as the documentation says it should:
CREATE (john:Person {name: 'John'})
CREATE (joe:Person {name: 'Joe'})
CREATE (steve:Person {name: 'Steve'})
CREATE (sara:Person {name: 'Sara'})
CREATE (maria:Person {name: 'Maria'})
CREATE (john)-[:FRIEND]->(joe)-[:FRIEND]->(steve) CREATE (john)-[:FRIEND]->(sara)-[:FRIEND]->(maria)
Is supposed to work like:
MATCH (user)-[:FRIEND]->(follower) WHERE user.name IN ['Joe', 'John', 'Sara', 'Maria', 'Steve'] AND follower.name =~ 'S.*' RETURN user.name, follower.name
gives: +
----------------------+ |
john.name | fof.name |
+----------------------+
| "John" | "Maria" | |
"John" | "Steve" |
+----------------------+ 2 rows
but instead I get:
(no changes, no records)
I am literally copying/pasting code from the manual into neo4j and getting unexpected results. Any help appreciated.
EDIT: I was copying code in one line at a time and executing one line at a time. IF I copy the entire block of code and execute it as a block, it works fine. I still don't understand why neo4j doesn't work the same when I execute one line at a time.
Upvotes: 0
Views: 121
Reputation: 1137
If you execute it one line at a time, the variable names go out of scope. That's the thing before the :Person. You could just as well create nodes with
CREATE (:Person {name:'John'})
But when you execute by itself
CREATE (a:Person {name:'John'})
then the variable name a
is subsequently lost in the next line. Hence, when you execute that last line by itself that defines the relationships, the variable names are meaningless. When you execute all of the lines together, then the variable definitions are maintained and it works.
Upvotes: 2