A* shortest-path with edge weights
Weighted shortest path between two nodes, bounded depth, in pure SQL.
A logistics graph has routes edges with cost and duration weights. Find the cheapest path from warehouse:NYC to customer:9912, max 5 hops. No external graph DB, no Dijkstra implementation in your service.
sql
PATH FROM 'warehouse:NYC' TO 'customer:9912'
EDGE LABEL = 'ROUTE'
WEIGHT BY (e) -> e.cost
ALGORITHM 'astar'
MAX DEPTH 5;
-- Returns the ordered edge sequence + total cost.
-- Switch ALGORITHM to 'dijkstra' for unweighted heuristic-free.