Cypher Labels Function

labels returns a list containing the string representations for all the labels of a node.

Syntax:labels(node)

Returns: A list containing String elements.

Arguments

NameDescription
nodeAn expression that returns a single node.

Example

MATCH (a:Person {name:"Carl"})
RETURN labels(a)

The value returned will be a list containing all Labels of a node. For example, the result might look like-

["Person"]

Note– If a node contains more than one labels, then all the labels will be present in the list of labels returned by the labels() function.

Considerations

  • labels(null) returns null.

Example

CREATE (a:Person {name:"foo"})-[:KNOWS]->(:Person {name:"bar"})
RETURN labels(a)

Returns the following Result

labels(a)
["Person"]

Example

CREATE (:Person {name:"Elon"})-[:FOUNDED]->(c:Company {name:"SpaceX"})
RETURN labels(c)

Returns the following Result

labels(c)
["Company"]

Example

CREATE (a:Person :Entrepreneur {name:"Elon"})-[:FOUNDED]->(:Company {name:"SpaceX"})
RETURN labels(a)

Returns the following Result

labels(a)
["Person", "Entrepreneur"]

Note- Notice how all the labels are returned in the form of a list if the node has multiple labels.

Example

RETURN labels(null)

Returns the following Result

labels(null)
null

Note- labels(null) return null.

Learn More