In part 1 we discussed the composite datatypes part 1. Now in part 2 we will discuss part more on composite datatypes. Our focus would be on Maps.
Maps:
You can construct maps in cypher.
A simple map using an agtypes.
Query:
The below query represents a literal maps with simple Data types.
SELECT *
FROM cypher('graph_name', $$
WITH {int_key: 1, float_key: 1.0, numeric_key: 1::numeric, bool_key: true, string_key: 'Value'} as m
RETURN m
$$) AS (m agtype);
It returns the map in the graph.
Maps using Composite Data types:
A map can also contain composite data types e.g. lists and other maps.
Query:
SELECT *
FROM cypher('graph_name', $$
WITH {listKey: [{inner: 'Map1'}, {inner: 'Map2'}], mapKey: {i: 0}} as m
RETURN m
$$) AS (m agtype);
The above query will return the list and map on the screen.
You can also access the properties inside the map while querying. For example below query will return the value of the int key which in turn is 1.
Query:
SELECT *
FROM cypher('graph_name', $$
WITH {int_key: 1, float_key: 1.0, numeric_key: 1::numeric, bool_key: true, string_key: 'Value'} as m
RETURN m.int_key
$$) AS (int_key agtype);
You can also access list elements in the maps.
Query:
The below query contains a list of maps. You can access the contents of the list using square brackets and an index number in it.
SELECT *
FROM cypher('graph_name', $$
WITH {listKey: [{inner: 'Map1'}, {inner: 'Map2'}], mapKey: {i: 0}} as m
RETURN m.listKey[0]
$$) AS (m agtype);
You can also read about lists in the part 1 of the blog here.
References:
You can follow for more content on age website and github.
Top comments (0)