Cypher Keys Function

keys returns a list containing the string representations for all the property names of a node, relationship, or map.

Syntax:keys(expression)

Returns: A list containing String elements.

Arguments

NameDescription
expressionAn expression that returns a node, a relationship, or a map.

Example

MATCH (a:Person {name:"Elon"})
RETURN keys(a)

The value returned will be a list of all the property names of the node a as a string representation. For example, in this case, the result might look like-

["name","date_of_birth","age", "profession"]

Considerations

  • keys(null) returns null.

Example

CREATE (a:Person {name:"foo", country:"India"})-[:KNOWS]->(:Person {name:"bar"})
RETURN keys(a)

Returns the following Result

keys(a)
["name", "country"]

Example

CREATE (a:Person {name:"foo", country:"India"})-[:KNOWS]->(:Person {name:"bar"})
RETURN keys(a)

Returns the following Result

keys(a)
["name", "country"]

Example

CREATE (a:Person)
RETURN keys(a)

Returns the following Result

keys(a)
[]

Example

CREATE (:Person {name:"foo", country:"India"})-[b:KNOWS]->(:Person {name:"bar"})
RETURN keys(b)

Returns the following Result

keys(b)
[]

Example

CREATE (:Person {name:”Elon”, country:”USA”})-[b:FOUNDER_OF {founded_in:2002}]->(:Company {name:”SpaceX”})
RETURN keys(b)

Returns the following Result

keys(a)
["founder_of"]

Example

RETURN keys({key1:"value1", key2:"value2", key3:"value3"})

Returns the following Result

keys({key1:"value1", key2:"value2", key3:"value3"})
["key1", "key2", "key3"]

Notekeys() function can be used with Map too.

Example

RETURN keys(null)

Returns the following Result

keys(null)
null

Notekeys(null) returns null.

Learn More