type()
returns the string representation of the relationship type.
Syntax:type(relationship)
Returns: A String.
Arguments
Name | Description |
relationship | An expression that returns a relationship. |
Example
MATCH (:Person {name:"Elon Musk"})-[b]->(:Person {name:"Talulah Riley"})
RETURN type(b)
The value returned will be the type of relationship that exists between two nodes of the label Person with the names Elon Musk and Talulah Riley. Only the relationships which go from start node to the end node will be listed. The value returned in this case for example might me “Partner”.
Considerations
type(null)
returnsnull
.
Example
CREATE (:Person {name:"Elon Musk"})-[b:KNOWS]->(:Person {name:"Larry Ellison"})
RETURN type(b)
Returns the following Result
type(b) |
"KNOWS" |
Example
CREATE (:Person {name:"Elon Musk"})-[b:OWNS]->(:Person {name:"SpaceX"})
RETURN type(b)
Returns the following Result
type(b) |
"OWNS" |
Example
RETURN type(null)
Returns the following Result
type(b) |
null |
Example
MATCH (:Person {name:"Elon Musk"})-[b]->(:Person)
RETURN type(b)
The result will contain the types of all the relationships which exist between the node with label Person and value of Elon Musk for the property name and all other nodes with the label Person. The results returned from such a query will then be(for a particular graph containing this information).
type(b) |
FATHER_OF |
Note– For the sake of simplicity in this example we have shown one type of relationship only once. In practical cases, each type of relationship will be returned as many times as it occurs in the given graph for the given match pattern. For example if the Person Elon Musk owns 4 companies, then OWNS relationship will be printed 4 times.