surfaceanalysisshortest_path
Analysisscalar · returns json

SHORTEST_PATH

Shortest path between two nodes on an ad-hoc edge list (NetworkX)

Per-row — runs once for each row.

analysisdeterministicjson

Arguments

nametypedescription
edgesJSON
sourceVARCHAR
targetVARCHAR

About

Shortest path on an ad-hoc edge list. Takes a JSON array of edges, a source node, and a destination node, returns the shortest path as a JSON object with `path` (list of nodes) and `length` (total weight). Usage: -- Direct call on a literal graph SELECT shortest_path( JSON('[["A","B",1],["B","C",2],["A","C",5],["C","D",1]]'), 'A', 'D' ); -- → {"path": ["A","B","C","D"], "length": 4} -- On a table of edges SELECT shortest_path( (SELECT JSON_GROUP_ARRAY(JSON_ARRAY(src, dst, weight)) FROM edges), 'Alice', 'Bob' ); The edge list is treated as directed. Symmetrize if you want an undirected shortest path.

Examples

Shortest path A→D picks the weighted route via B+C (length 6)

SELECT
  shortest_path (
    JSON(
      '[["A","B",2],["B","C",3],["A","C",10],["C","D",1]]'
    ),
    'A',
    'D'
  );

Nearby rabbit holes

same domain
Climb back to The Looking Glass