Search code examples
memgraphdb

Does Memgraph provide a function to get the length of a property variable?


How can you find the length of a property variable of a node or edge? Something like LENGTH() function doesn't exist in Cypher.

Does Memgraph have a built-in function or a way to return the length of a property variable?


Solution

  • In the Graph Style Script (GSS) built-in functions, there is a Size function that can return the size of a property variable. If the value is of type Node, it returns the size of node properties. If the value is of type Relationship, it returns the size of relationship properties. For example, Size(Property(node, "name")) returns the size of the node's name property. You can find more details about this function in the official documenataion.

    In the Python API, there is a len function that can be used to get the number of properties on a vertex or edge. For example, len(vertex.properties) or len(edge.properties). You can find more details about this function in the reference guide.