Here I have two nodes with the property ‘name’ that contains the first name and last name of a person. I create the vertices as:
SELECT * FROM cypher('graph', $$
CREATE (n:Person {name : "Michael Stone", age : 20}), (m: Person {name : "Michael Douglas", age: 19})
RETURN n, m
$$) AS (n agtype, m agtype);
I want to retrieve the nodes where the first name is Michael. How can it be done? Is there any clause such as "LIKE" (as in postgreqsl) in AGE?
3
Answers
You can use regular expression matching to find a substring within a string. In your case, it would look like:
Note that the ‘.’ operator is a wildcard and matches against any possible character, while the ‘*’ operator matches with 0 or more of the previous character (in this case it can be 0 or more of any possible character).
I think you can use like operator like this
To get all the names starting with Michael as first name.
One of the way to retrieve the nodes where the first name is Michael, is through following query.
Here in the query the MATCH clause is used to find all the node labeled as ‘Person’, WHERE clause is used to filter the results based on the first name of the person then the split function is called to split the name property based on the space delimiter and retrieve the first element of the resulting array.