I am using Memgraph Platform 2.6.5 and I want to check whether the property of a node is a list. I see there is a type
function for relationships but would be good to have some kind of data type filtering for properties. I tried using the size
function but it also works on strings and paths so it can't tell if a property is a list or not. Any idea on how to do that?
Here is an example of a small trick on how to do that:
If you have a node with list and string properties:
CREATE (n:Node {list: [1, 2, 3, 4, 5, 6, 7, 8], str: "myString"});
And then run:
MATCH (n:Node)
RETURN size(n.list + 11) = size(n.list)+1 AS isList;
I get true
.
Otherwise, if I run this:
MATCH (n:Node)
RETURN size(n.str + 11) = size(n.str)+1 AS isList;
I get false
.
This is because if you add a number consisting of two chars to a string, you get string which size has increased by 2. But, if you add the same number to a list, list size increased by 1.
Besides that, you can always create a custom procedure in Memgraph to extend Cypher query language. These procedures can be written in Python, C/C++ or Rust, and here is a how-to guide.