Skip to content

List functions

Nebula Graph supports the following list functions:

Function Description
keys(expr) Returns a list containing the string representations for all the property names of vertices, edges, or maps.
labels(vertex) Returns the list containing all the tags of a vertex.
nodes(path) Returns the list containing all the vertices in a path.
range(start, end [, step]) Returns the list containing all the fixed-length steps in [start,end]. step is 1 by default.
relationships(path) Returns the list containing all the relationships in a path.
reverse(list) Returns the list reversing the order of all elements in the original list.
tail(list) Returns all the elements of the original list, excluding the first one.
head(list) Returns the first element of a list.
last(list) Returns the last element of a list.
coalesce(list) Returns the first not null value in a list.
reduce() See reduce() function.

Note

If the argument is NULL, the output is undefined.

Examples

nebula> WITH [NULL, 4923, 'abc', 521, 487] AS ids \
        RETURN reverse(ids), tail(ids), head(ids), last(ids), coalesce(ids);
+-----------------------------------+-------------------------+-----------+-----------+---------------+
| reverse(ids)                      | tail(ids)               | head(ids) | last(ids) | coalesce(ids) |
+-----------------------------------+-------------------------+-----------+-----------+---------------+
| [487, 521, "abc", 4923, __NULL__] | [4923, "abc", 521, 487] | __NULL__  | 487       | 4923          |
+-----------------------------------+-------------------------+-----------+-----------+---------------+

nebula> MATCH (a:player)-[r]->() \
        WHERE id(a) == "player100" \
        RETURN labels(a),  keys(r);
+------------+----------------------------+
| labels(a)  | keys(r)                    |
+------------+----------------------------+
| ["player"] | ["degree"]                 |
| ["player"] | ["degree"]                 |
| ["player"] | ["end_year", "start_year"] |
+------------+----------------------------+

nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) \
        WHERE a.player.name == "Tim Duncan" AND c.team.name == "Spurs" \
        RETURN nodes(p);
+-----------------------------------------------------------------------------------------------------------------------------------------------+
| nodes(p)                                                                                                                                      |
+-----------------------------------------------------------------------------------------------------------------------------------------------+
| [("player100" :player{age: 42, name: "Tim Duncan"}), ("player101" :player{age: 36, name: "Tony Parker"}), ("team204" :team{name: "Spurs"})]   |
| [("player100" :player{age: 42, name: "Tim Duncan"}), ("player125" :player{age: 41, name: "Manu Ginobili"}), ("team204" :team{name: "Spurs"})] |
+-----------------------------------------------------------------------------------------------------------------------------------------------+

nebula> MATCH p = (a:player)-[]->(b)-[]->(c:team) WHERE a.player.name == "Tim Duncan" AND c.team.name == "Spurs" RETURN relationships(p);
+-----------------------------------------------------------------------------------------------------------------------------+
| relationships(p)                                                                                                            |
+-----------------------------------------------------------------------------------------------------------------------------+
| [[:follow "player100"->"player101" @0 {degree: 95}], [:serve "player101"->"team204" @0 {end_year: 2018, start_year: 1999}]] |
| [[:follow "player100"->"player125" @0 {degree: 95}], [:serve "player125"->"team204" @0 {end_year: 2018, start_year: 2002}]] |
+-----------------------------------------------------------------------------------------------------------------------------+

Last update: January 13, 2022