Skill 1.3.6

Write graph queries that use the MATCH operator

Key Concepts

The MATCH predicate appears in the WHERE clause with ASCII-art patterns such as MATCH(Customer-(Bought)->Product), where node and edge tables are listed in the FROM clause. Patterns can chain hops, for example MATCH(c1-(b1)->p<-(b2)-c2) to find customers who bought the same product, and can be combined with ordinary predicates and AND. Arrow direction follows the edge from $from_id to $to_id.

SHORTEST_PATH inside MATCH finds paths of arbitrary length, written as MATCH(SHORTEST_PATH(p1(-(f)->p2)+)), with the node and edge tables in the path marked FOR PATH. Graph aggregate functions such as STRING_AGG(p2.Name, '->') WITHIN GROUP (GRAPH PATH), COUNT and LAST_VALUE describe the path, and the quantifier {1,3} limits the number of hops.