### duckrouting_sequential_vertex_coloring example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example query that colors vertices and returns the first six nodes. The output shows node-color pairs with colors starting at 1. ```sql SELECT node, color FROM duckrouting_sequential_vertex_coloring( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id') WHERE node <= 6 ORDER BY node; -- → node color -- → 1 1 -- → 2 1 -- → 3 2 -- → 4 2 -- → 5 1 -- → 6 2 ``` -------------------------------- ### Install duckrouting from community Source: https://github.com/am2222/duckrouting/blob/main/docs/guide/getting-started.md Installs the duckrouting extension from the community repository and loads it. ```sql INSTALL duckrouting FROM community; LOAD duckrouting; ``` -------------------------------- ### duckrouting_max_flow_min_cost_cost example with output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/flow.md Example query for duckrouting_max_flow_min_cost_cost that returns only the total cost of the cheapest max flow. The output is 430.0 for the same edges and source/sink as the previous example. ```sql SELECT * FROM duckrouting_max_flow_min_cost_cost( 'SELECT id, source, target, capacity, reverse_capacity, cost, reverse_cost FROM edges', 11, 12); -- → 430.0 ``` -------------------------------- ### duckrouting_dijkstra_near_cost example with cap Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Example call to duckrouting_dijkstra_near_cost with an array of start vertices and a single end vertex, using the cap => 2 named parameter. The output shows start_vid, end_vid, and agg_cost for the two returned rows. ```sql SELECT * FROM duckrouting_dijkstra_near_cost( 'SELECT id, source, target, cost, reverse_cost FROM edges', [10, 11, 1], 6, cap => 2); -- → start_vid end_vid agg_cost -- → 10 6 1.0 -- → 11 6 2.0 ``` -------------------------------- ### duckrouting_bandwidth example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example query using duckrouting_bandwidth on a simple edges table. The expected output is 5. ```sql SELECT * FROM duckrouting_bandwidth( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → 5 ``` -------------------------------- ### duckrouting_hawick_circuits example call and output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example call to duckrouting_hawick_circuits with a full edges query, filtered to path_id 1. The output shows path_seq starting at 0 and the final edge -1 when returning to the start vertex. ```sql SELECT path_id, path_seq, node, edge, agg_cost FROM duckrouting_hawick_circuits( 'SELECT id, source, target, cost, reverse_cost FROM edges') WHERE path_id = 1; -- → path_id path_seq node edge agg_cost -- → 1 0 5 1 0.0 -- → 1 1 6 1 1.0 -- → 1 2 5 -1 2.0 ``` -------------------------------- ### duckrouting_dijkstra_cost example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Example call to duckrouting_dijkstra_cost with a single start and end vertex. Returns one row per reachable pair with start_vid, end_vid, and agg_cost; here the cost from 6 to 10 is 5.0. ```sql SELECT * FROM duckrouting_dijkstra_cost( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 10); -- → start_vid end_vid agg_cost -- → 6 10 5.0 ``` -------------------------------- ### duckrouting_strong_components: example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/components.md Example query that counts members per strong component. Same column shape as connected_components. ```sql SELECT component, count(*) AS members FROM duckrouting_strong_components( 'SELECT id, source, target, cost, reverse_cost FROM edges') GROUP BY component ORDER BY component; -- → component members -- → 1 13 -- → 2 2 -- → 13 2 ``` -------------------------------- ### duckrouting_make_connected: example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/components.md Example query that lists vertex pairs to join. Joining n components takes n-1 pairs; an already-connected graph returns nothing. The specific vertices are Boost's choice and follow vertex ordering, so do not assert on them. ```sql SELECT * FROM duckrouting_make_connected( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → seq start_vid end_vid -- → 1 9 2 -- → 2 4 13 ``` -------------------------------- ### duckrouting_transitive_closure example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example query using duckrouting_transitive_closure on a subset of edges. The output shows the node and targets array, with targets sorted ascending. The example includes the expected result set. ```sql SELECT * FROM duckrouting_transitive_closure( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id IN (2,3,5,11,12,13,15)') ORDER BY node; -- → node targets -- → 6 [] -- → 8 [12, 16, 17] -- → 10 [6, 11, 12, 16, 17] -- → 11 [12, 16, 17] -- → 12 [16, 17] -- → 15 [6, 10, 11, 12, 16, 17] ``` -------------------------------- ### duckrouting_max_flow_min_cost example with output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/flow.md Example query for duckrouting_max_flow_min_cost using an edges table with capacity, reverse_capacity, cost, and reverse_cost columns. The output shows the flow, cost, and agg_cost for each edge in the cheapest max flow from source 11 to sink 12. ```sql SELECT edge, source, target, flow, cost, agg_cost FROM duckrouting_max_flow_min_cost( 'SELECT id, source, target, capacity, reverse_capacity, cost, reverse_cost FROM edges', 11, 12); -- → edge source target flow cost agg_cost -- → 8 11 7 100.0 100.0 100.0 -- → 10 7 8 100.0 100.0 200.0 -- → 11 11 12 130.0 130.0 330.0 -- → 12 8 12 100.0 100.0 430.0 ``` -------------------------------- ### duckrouting_floyd_warshall example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/all-pairs.md Example query for duckrouting_floyd_warshall. It selects all pairs from edges with id < 5 and orders by start_vid and end_vid. The output shows the resulting start_vid, end_vid, and agg_cost rows. ```sql SELECT * FROM duckrouting_floyd_warshall( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id < 5') ORDER BY start_vid, end_vid; -- → start_vid end_vid agg_cost -- → 5 6 1.0 -- → 5 7 2.0 -- → 6 5 1.0 -- → 6 7 1.0 -- → 7 5 2.0 -- → 7 6 1.0 -- → 10 5 2.0 -- → 10 6 1.0 -- → 10 7 2.0 -- → 15 5 3.0 -- → 15 6 2.0 -- → 15 7 3.0 -- → 15 10 1.0 ``` -------------------------------- ### duckrouting_dijkstra many-to-many example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Many-to-many example passing BIGINT[] lists for start and end vertices. Lists are de-duplicated and sorted, and pairs with coinciding endpoints are dropped. ```sql SELECT DISTINCT start_vid, end_vid FROM duckrouting_dijkstra( 'SELECT id, source, target, cost, reverse_cost FROM edges', [7, 10], [10, 15]); -- → start_vid end_vid -- → 7 10 -- → 7 15 -- → 10 15 ``` -------------------------------- ### duckrouting_johnson example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/all-pairs.md Example query for duckrouting_johnson. It selects all pairs from edges with id < 5 but omits reverse_cost, making every edge one-way. The output shows three rows, fewer than the floyd_warshall example because reverse_cost is absent. ```sql SELECT * FROM duckrouting_johnson( 'SELECT source, target, cost FROM edges WHERE id < 5') ORDER BY start_vid, end_vid; -- → start_vid end_vid agg_cost -- → 5 6 1.0 -- → 5 7 2.0 -- → 6 7 1.0 ``` -------------------------------- ### Example query and output for duckrouting_max_cardinality_match Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/flow.md Example SQL query using the function with a SELECT statement on the edges table, followed by the resulting edge IDs. ```sql SELECT * FROM duckrouting_max_cardinality_match( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → edge -- → 1 -- → 5 -- → 6 -- → 13 -- → 14 -- → 16 -- → 17 -- → 18 ``` -------------------------------- ### duckrouting_articulation_points: example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/components.md Example query that lists all articulation points. Returns a single node column. ```sql SELECT * FROM duckrouting_articulation_points( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → node -- → 3 -- → 6 -- → 7 -- → 8 ``` -------------------------------- ### Query duckrouting_driving_distance with start vertex 11 and distance 2.0 Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Example query for the duckrouting_driving_distance function. It selects the depth, predecessor, node, edge, and aggregate cost from the function called with an edges SQL, a start vertex of 11, and a distance of 2.0. The output shows the shortest-path tree with the root at depth 0 and its own predecessor with edge -1. Note that when paths tie on cost, the reported path is not defined and may differ from pgRouting; assert on agg_cost rather than a specific tie-break. ```sql SELECT depth, pred, node, edge, agg_cost FROM duckrouting_driving_distance( 'SELECT id, source, target, cost, reverse_cost FROM edges', 11, 2.0); -- → depth pred node edge agg_cost -- → 0 11 11 -1 0.0 -- → 1 11 7 8 1.0 -- → 1 11 12 11 1.0 -- → 1 11 16 9 1.0 -- → 2 7 3 7 2.0 -- → 2 7 6 4 2.0 -- → 2 7 8 10 2.0 -- → 2 16 15 16 2.0 -- → 2 12 17 13 2.0 ``` -------------------------------- ### Basic via routing example with output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Example query routing through vertices 5, 1, and 8. The output shows two legs with path_id 1 and 2. The last row of leg 1 has edge -1, and the last row of the route has edge -2. agg_cost restarts each leg while route_agg_cost accumulates. ```sql SELECT path_id, node, edge, agg_cost, route_agg_cost FROM duckrouting_dijkstra_via( 'SELECT id, source, target, cost, reverse_cost FROM edges', [5, 1, 8]); -- → path_id node edge agg_cost route_agg_cost -- → 1 5 1 0.0 0.0 -- → 1 6 4 1.0 1.0 -- → 1 7 7 2.0 2.0 -- → 1 3 6 3.0 3.0 -- → 1 1 -1 4.0 4.0 -- → 2 1 6 0.0 4.0 -- → 2 3 7 1.0 5.0 -- → 2 7 10 2.0 6.0 -- → 2 8 -2 3.0 7.0 ``` -------------------------------- ### Create edges table and run duckrouting_dijkstra Source: https://github.com/am2222/duckrouting/blob/main/README.md Shows the minimal setup for a routing graph: a table with id, source, target, cost, and optional reverse_cost, then a call to duckrouting_dijkstra with a SQL string as the first argument. The output shows the path from node 5 to node 7 with cumulative costs. ```sql CREATE TABLE edges ( id BIGINT, source BIGINT, target BIGINT, cost DOUBLE, reverse_cost DOUBLE ); INSERT INTO edges VALUES (1, 5, 6, 1, 1), (2, 6, 10, -1, 1), (3, 10, 15, -1, 1), (4, 6, 7, 1, 1); SELECT node, edge, agg_cost FROM duckrouting_dijkstra( 'SELECT id, source, target, cost, reverse_cost FROM edges', 5, 7); -- node | edge | agg_cost -- 5 | 1 | 0.0 -- 6 | 4 | 1.0 -- 7 | -1 | 2.0 ``` -------------------------------- ### Get two cheapest pairs with cap => 2 Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Uses cap => 2 to return the two cheapest (start, end) pairs across all starts. Here the nearest pairs are from 10 to 6 and from 11 to 6. ```sql SELECT start_vid, end_vid, node, edge, agg_cost FROM duckrouting_dijkstra_near( 'SELECT id, source, target, cost, reverse_cost FROM edges', [10, 11, 1], 6, cap => 2); -- → start_vid end_vid node edge agg_cost -- → 10 6 10 2 0.0 -- → 10 6 6 -1 1.0 -- → 11 6 11 8 0.0 -- → 11 6 7 4 1.0 -- → 11 6 6 -1 2.0 ``` -------------------------------- ### duckrouting_cuthill_mckee_ordering example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example query using duckrouting_cuthill_mckee_ordering on the full edges table. The output is a list of node IDs ordered by seq, showing the resulting permutation. ```sql SELECT list(node ORDER BY seq) FROM duckrouting_cuthill_mckee_ordering( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → [13, 14, 2, 4, 5, 1, 6, 3, 10, 7, 9, 15, 11, 8, 16, 12, 17] ``` -------------------------------- ### duckrouting_breadth_first_search example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example query for breadth-first search with root 6 and max_depth 2. The output shows vertices visited nearest first; vertex 10 is missing because edge 2 has cost -1, but appears when directed => false. ```sql SELECT seq, depth, pred, node, edge FROM duckrouting_breadth_first_search( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 6, 2); -- → seq depth pred node edge -- → 1 0 6 6 -1 -- → 2 1 6 5 1 -- → 3 1 6 7 4 -- → 4 2 7 3 7 -- → 5 2 7 11 8 -- → 6 2 7 8 10 ``` -------------------------------- ### duckrouting_dag_shortest_path example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example SQL query using duckrouting_dag_shortest_path, selecting path_seq, node, edge, and agg_cost. The output shows the path from node 5 to node 11 with agg_cost values from 0.0 to 3.0. ```sql SELECT path_seq, node, edge, agg_cost FROM duckrouting_dag_shortest_path( 'SELECT id, source, target, cost FROM edges', 5, 11); -- → path_seq node edge agg_cost -- → 1 5 1 0.0 -- → 2 6 4 1.0 -- → 3 7 8 2.0 -- → 4 11 -1 3.0 ``` -------------------------------- ### duckrouting_depth_first_search example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example query for depth-first search with root 6. The output shows depth rising and falling as the search backtracks; seq 6 dropping to depth 2 indicates the backtrack from vertex 3's branch. ```sql SELECT seq, depth, pred, node, edge FROM duckrouting_depth_first_search( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 6); -- → seq depth pred node edge -- → 1 0 6 6 -1 -- → 2 1 6 5 1 -- → 3 1 6 7 4 -- → 4 2 7 3 7 -- → 5 3 3 1 6 -- → 6 2 7 11 8 -- → ... ``` -------------------------------- ### duckrouting_biconnected_components: example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/components.md Example query that counts edges per biconnected component. Components holding a single edge are exactly the bridges. ```sql SELECT component, count(*) AS edges FROM duckrouting_biconnected_components( 'SELECT id, source, target, cost, reverse_cost FROM edges') GROUP BY component ORDER BY component; -- → component edges -- → 1 1 -- → 2 12 -- → 6 1 -- → 7 1 -- → 14 1 -- → 17 1 -- → 18 1 ``` -------------------------------- ### Depth-first traversal example with output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/spanning-trees.md Shows a depth-first traversal using duckrouting_prim_dd with root 6 and distance 3.5. The output demonstrates that depth first descends and backtracks, so depth rises and falls. ```sql SELECT seq, depth, pred, node, edge, agg_cost FROM duckrouting_prim_dd( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 6, 3.5); -- → seq depth pred node edge agg_cost -- → 1 0 6 6 -1 0.0 -- → 2 1 6 5 1 1.0 -- → 3 1 6 10 2 1.0 -- → 4 2 10 3 3 2.0 -- → 5 2 10 11 5 2.0 -- → 6 3 11 16 9 3.0 -- → 7 3 11 12 11 3.0 -- → 8 1 6 7 4 1.0 -- → 9 2 7 3 7 2.0 -- → 10 3 3 1 6 3.0 -- → 11 2 7 8 10 2.0 -- → 12 3 8 9 14 3.0 ``` -------------------------------- ### duckrouting_dijkstra directed example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Directed example of duckrouting_dijkstra from vertex 6 to 10. The result shows the path rows with seq, path_seq, start_vid, end_vid, node, edge, cost, and agg_cost; the final row has edge -1 and cost 0.0, and agg_cost on the last row is the total cost. ```sql SELECT * FROM duckrouting_dijkstra( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 10); -- → seq path_seq start_vid end_vid node edge cost agg_cost -- → 1 1 6 10 6 4 1.0 0.0 -- → 2 2 6 10 7 8 1.0 1.0 -- → 3 3 6 10 11 9 1.0 2.0 -- → 4 4 6 10 16 16 1.0 3.0 -- → 5 5 6 10 15 3 1.0 4.0 -- → 6 6 6 10 10 -1 0.0 5.0 ``` -------------------------------- ### duckrouting_prim example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/spanning-trees.md Example query using duckrouting_prim to count edges and sum costs. The output shows 11 edges and a total cost of 11.0 for a filtered edge set. ```sql SELECT count(*) AS edges, sum(cost) AS total FROM duckrouting_prim( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id < 14'); -- → edges total -- → 11 11.0 ``` -------------------------------- ### duckrouting_betweenness_centrality example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example query using duckrouting_betweenness_centrality on a subset of edges, ordered by vid. The expected output shows centrality values for each vertex. ```sql SELECT * FROM duckrouting_betweenness_centrality( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id < 5') ORDER BY vid; -- → vid centrality -- → 5 0.0 -- → 6 0.5 -- → 7 0.0 -- → 10 0.25 -- → 15 0.0 ``` -------------------------------- ### duckrouting_bridges: example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/components.md Example query that lists all bridges. Computed as biconnected components consisting of exactly one edge. ```sql SELECT * FROM duckrouting_bridges( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → edge -- → 1 -- → 6 -- → 7 -- → 14 -- → 17 -- → 18 ``` -------------------------------- ### duckrouting_astar_cost example with multiple end vertices Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/astar.md Example calling `duckrouting_astar_cost` with an edges SQL query including coordinates, from vertex 6 to vertices 10 and 12. The output shows total costs for each reachable pair. ```sql SELECT * FROM duckrouting_astar_cost( 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges', 6, [10, 12]); -- → start_vid end_vid agg_cost -- → 6 10 5.0 -- → 6 12 3.0 ``` -------------------------------- ### duckrouting_connected_components: example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/components.md Example query that counts members per component. The component label is the smallest node id in the component, stable across runs. ```sql SELECT component, count(*) AS members FROM duckrouting_connected_components( 'SELECT id, source, target, cost, reverse_cost FROM edges') GROUP BY component ORDER BY component; -- → component members -- → 1 13 -- → 2 2 -- → 13 2 ``` -------------------------------- ### duckrouting_is_planar example on K5 graph Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example query using duckrouting_is_planar on a K5 graph (five vertices all joined). The expected output is false, as K5 is non-planar. ```sql SELECT * FROM duckrouting_is_planar( 'SELECT * FROM (VALUES (1,1,2,1.0,1.0),(2,1,3,1.0,1.0),(3,1,4,1.0,1.0),(4,1,5,1.0,1.0), (5,2,3,1.0,1.0),(6,2,4,1.0,1.0),(7,2,5,1.0,1.0), (8,3,4,1.0,1.0),(9,3,5,1.0,1.0),(10,4,5,1.0,1.0)) t(id,source,target,cost,reverse_cost)'); -- → false ``` -------------------------------- ### duckrouting_edge_disjoint_paths example with output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/flow.md Example query for duckrouting_edge_disjoint_paths using an edges table with cost and reverse_cost. The output shows two independent routes from 11 to 12 that share no edge, with path_id, path_seq, node, and edge columns. ```sql SELECT path_id, path_seq, node, edge FROM duckrouting_edge_disjoint_paths( 'SELECT id, source, target, cost, reverse_cost FROM edges', 11, 12); -- → path_id path_seq node edge -- → 1 1 11 8 -- → 1 2 7 10 -- → 1 3 8 12 -- → 1 4 12 -1 -- → 2 1 11 11 -- → 2 2 12 -1 ``` -------------------------------- ### Run duckrouting shell and tests Source: https://github.com/am2222/duckrouting/blob/main/README.md Run the built DuckDB shell with the extension loaded and execute the SQL test suite. Geometry tests require INSTALL spatial and are skipped otherwise. ```shell ./build/release/duckdb # a shell with the extension already loaded make test # run the SQL test suite ``` -------------------------------- ### duckrouting_is_planar example on a planar graph Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example query using duckrouting_is_planar on a simple edges table. The expected output is true, indicating the graph is planar. ```sql SELECT * FROM duckrouting_is_planar( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → true ``` -------------------------------- ### Breadth-first traversal example with output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/spanning-trees.md Shows a breadth-first traversal using duckrouting_kruskal_bfs with root 6 and max_depth 2. The output demonstrates that breadth-first never goes back up, with depth increasing monotonically. ```sql SELECT depth, pred, node, edge FROM duckrouting_kruskal_bfs( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', 6, 2); -- → depth pred node edge -- → 0 6 6 -1 -- → 1 6 5 1 -- → 1 6 7 4 -- → 2 7 3 7 -- → 2 7 8 10 ``` -------------------------------- ### duckrouting_bipartite non-bipartite example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example query on a triangle graph (odd cycle) returns zero rows, indicating the graph is not bipartite. ```sql SELECT count(*) FROM duckrouting_bipartite( 'SELECT * FROM (VALUES (1,1,2,1.0,1.0),(2,2,3,1.0,1.0),(3,3,1,1.0,1.0)) t(id,source,target,cost,reverse_cost)'); -- → 0 ``` -------------------------------- ### duckrouting_bellman_ford example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example SQL query using duckrouting_bellman_ford with directed=true, selecting path_seq, node, edge, and agg_cost. The output shows the path from node 6 to node 10 with agg_cost values from 0.0 to 5.0. ```sql SELECT path_seq, node, edge, agg_cost FROM duckrouting_bellman_ford( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 10, true); -- → path_seq node edge agg_cost -- → 1 6 4 0.0 -- → 2 7 8 1.0 -- → 3 11 9 2.0 -- → 4 16 16 3.0 -- → 5 15 3 4.0 -- → 6 10 -1 5.0 ``` -------------------------------- ### duckrouting_astar example with heuristic 3 and factor 3.5 Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/astar.md Example calling `duckrouting_astar` with an edges SQL query that includes coordinates, from vertex 6 to 10, using heuristic 3 (squared Euclidean) and factor 3.5. The output shows path_seq, node, edge, and agg_cost, resulting in total cost 5, which matches the Dijkstra result for the same pair. ```sql SELECT path_seq, node, edge, agg_cost FROM duckrouting_astar( 'SELECT id, source, target, cost, reverse_cost, x1, y1, x2, y2 FROM edges', 6, 10, heuristic => 3, factor => 3.5); -- → path_seq node edge agg_cost -- → 1 6 4 0.0 -- → 2 7 8 1.0 -- → 3 11 9 2.0 -- → 4 16 16 3.0 -- → 5 15 3 4.0 -- → 6 10 -1 5.0 ``` -------------------------------- ### duckrouting_topological_sort example query Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/traversal.md Example query using duckrouting_topological_sort on the full edges table. The output is an error message indicating the graph contains a cycle, so it is not a DAG. ```sql SELECT * FROM duckrouting_topological_sort( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → Invalid Input Error: the graph contains a cycle, so it is not a DAG ``` -------------------------------- ### duckrouting_kruskal example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/spanning-trees.md Example query using duckrouting_kruskal to count edges and sum costs. The output shows 14 edges and a total cost of 14.0 for a graph with 17 vertices in 3 components. ```sql SELECT count(*) AS edges, sum(cost) AS total FROM duckrouting_kruskal( 'SELECT id, source, target, cost, reverse_cost FROM edges'); -- → edges total -- → 14 14.0 ``` -------------------------------- ### Example query: duckrouting_dominator_tree with root 5 Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example SQL query that calls duckrouting_dominator_tree with root 5 and filters for vertices 1, 3, and 5. The output shows that vertex 1's idom is 3, vertex 3's idom is 7, and vertex 5's idom is 0 (root). ```sql SELECT vertex_id, idom FROM duckrouting_dominator_tree( 'SELECT id, source, target, cost, reverse_cost FROM edges', 5) WHERE vertex_id IN (1, 3, 5) ORDER BY vertex_id; -- → vertex_id idom -- → 1 3 -- → 3 7 -- → 5 0 ``` -------------------------------- ### duckrouting_ksp Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/ksp.md Returns up to k shortest loopless paths for each (start, end) combination, cheapest first. Supports multiple start and end vertex combinations and an optional directed flag. ```APIDOC ## duckrouting_ksp ### Description Returns up to `k` shortest **loopless** paths for every (start, end) combination, cheapest first. Returns `seq`, `path_id`, `path_seq`, `start_vid`, `end_vid`, `node`, `edge`, `cost` and `agg_cost`. ### Signatures ```sql TABLE duckrouting_ksp (edges_sql VARCHAR, start_vid BIGINT, end_vid BIGINT, k BIGINT) TABLE duckrouting_ksp (edges_sql VARCHAR, start_vid BIGINT, end_vid BIGINT[], k BIGINT) TABLE duckrouting_ksp (edges_sql VARCHAR, start_vid BIGINT[], end_vid BIGINT, k BIGINT) TABLE duckrouting_ksp (edges_sql VARCHAR, start_vid BIGINT[], end_vid BIGINT[], k BIGINT) -- each also accepts a trailing directed BOOLEAN, -- plus named directed => BOOLEAN and heap_paths => BOOLEAN ``` ### Parameters #### Input Parameters - **edges_sql** (VARCHAR) - Required - SQL query returning the edges of the graph with columns: id, source, target, cost, and optionally reverse_cost. - **start_vid** (BIGINT or BIGINT[]) - Required - Starting vertex identifier or array of starting vertex identifiers. - **end_vid** (BIGINT or BIGINT[]) - Required - Ending vertex identifier or array of ending vertex identifiers. - **k** (BIGINT) - Required - Maximum number of paths to return for each (start, end) pair. Must be at least 1. - **directed** (BOOLEAN) - Optional - If true, the graph is considered directed. Default is true. - **heap_paths** (BOOLEAN) - Optional - If true, also returns candidate paths generated by Yen's algorithm that were not selected. Default is false. ### Return Columns - **seq** (BIGINT) - Row sequence number. - **path_id** (BIGINT) - Identifier of the path. Runs across the whole result, not resetting per pair. - **path_seq** (BIGINT) - Sequence number of the node within the path. - **start_vid** (BIGINT) - Starting vertex identifier for this path. - **end_vid** (BIGINT) - Ending vertex identifier for this path. - **node** (BIGINT) - Identifier of the current node in the path. - **edge** (BIGINT) - Identifier of the edge used to reach this node. -1 for the last node. - **cost** (FLOAT) - Cost of traversing the edge from the previous node to this node. - **agg_cost** (FLOAT) - Aggregated cost from the start node to this node. ### Example Two ways to get from 6 to 17, both costing 4: ```sql SELECT path_id, path_seq, node, edge, agg_cost FROM duckrouting_ksp( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 17, 2); -- → path_id path_seq node edge agg_cost -- → 1 1 6 4 0.0 -- → 1 2 7 8 1.0 -- → 1 3 11 9 2.0 -- → 1 4 16 15 3.0 -- → 1 5 17 -1 4.0 -- → 2 1 6 4 0.0 -- → 2 2 7 10 1.0 -- → 2 3 8 12 2.0 -- → 2 4 12 13 3.0 -- → 2 5 17 -1 4.0 ``` Collapsing each path to its node sequence is often what you actually want: ```sql SELECT path_id, list_aggregate(list(node ORDER BY path_seq), 'string_agg', ',') AS route, max(agg_cost) AS cost FROM duckrouting_ksp( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 17, 2) GROUP BY path_id ORDER BY path_id; -- → path_id route cost -- → 1 6,7,11,16,17 4.0 -- → 2 6,7,8,12,17 4.0 ``` ### Notes - When several paths tie on cost, their order is not defined. Treat `path_id` as a grouping key, not as a stable ranking among equal costs. - If fewer than `k` distinct paths exist, fewer are returned; this is not an error. - With `heap_paths => true`, the result may exceed `k` because unselected candidate paths are also returned. - `k = 1` is exactly `duckrouting_dijkstra`. ``` -------------------------------- ### duckrouting_dijkstra_cost_matrix example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Example call to duckrouting_dijkstra_cost_matrix with a list of vertices and directed=false. Returns the cost of every ordered pair; with directed=false the matrix is symmetric, as shown by the reciprocal costs. ```sql SELECT * FROM duckrouting_dijkstra_cost_matrix( 'SELECT id, source, target, cost, reverse_cost FROM edges', [5, 6, 10], false); -- → start_vid end_vid agg_cost -- → 5 6 1.0 -- → 5 10 2.0 -- → 6 5 1.0 -- → 6 10 1.0 -- → 10 5 2.0 -- → 10 6 1.0 ``` -------------------------------- ### duckrouting_dijkstra undirected example Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/dijkstra.md Undirected example using directed => false. The same query takes edge 2 directly because its reverse_cost is traversable even though its cost is -1. ```sql SELECT node, edge, agg_cost FROM duckrouting_dijkstra( 'SELECT id, source, target, cost, reverse_cost FROM edges', 6, 10, directed => false); -- → node edge agg_cost -- → 6 2 0.0 -- → 10 -1 1.0 ``` -------------------------------- ### duckrouting_stoer_wagner example call and output Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/analysis.md Example call to duckrouting_stoer_wagner with a filtered edges query. The output shows one row per edge crossing the cut, with the total mincut value repeated on each row. ```sql SELECT * FROM duckrouting_stoer_wagner( 'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id < 17'); -- → seq edge cost mincut -- → 1 14 1.0 1.0 ``` -------------------------------- ### duckrouting_tsp with start_id Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/tsp.md Runs duckrouting_tsp on the same matrix but starts the tour at vertex 10. The tour order changes but the total cost remains 6.0. ```sql SELECT * FROM duckrouting_tsp('SELECT start_vid, end_vid, agg_cost FROM matrix', 10); -- → seq node cost agg_cost -- → 1 10 0.0 0.0 -- → 2 6 1.0 1.0 -- → 3 5 1.0 2.0 -- → 4 15 3.0 5.0 -- → 5 10 1.0 6.0 ``` -------------------------------- ### Example: One-way street network query with duckrouting_dijkstra Source: https://github.com/am2222/duckrouting/blob/main/docs/guide/edges-query.md Shows a SQL query using duckrouting_dijkstra with a dollar-quoted string to define the graph. The query selects edges from a streets table, computing cost and reverse_cost based on a oneway flag, and filters out closed streets. The dollar-quoting avoids escaping single quotes. ```sql SELECT * FROM duckrouting_dijkstra( $$ SELECT id, source, target, CASE WHEN oneway THEN travel_time ELSE travel_time END AS cost, CASE WHEN oneway THEN -1 ELSE travel_time END AS reverse_cost FROM streets WHERE NOT closed $$, 100, 250); ``` -------------------------------- ### duckrouting_max_flow usage examples Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/flow.md Shows two queries using duckrouting_max_flow: one with a single sink (11 to 12) returning 230.0, and one with multiple sinks ([5, 10, 12]) returning 340.0. The edges SQL must include id, source, target, capacity, and reverse_capacity. ```sql SELECT * FROM duckrouting_max_flow( 'SELECT id, source, target, capacity, reverse_capacity FROM edges', 11, 12); -- → 230.0 SELECT * FROM duckrouting_max_flow( 'SELECT id, source, target, capacity, reverse_capacity FROM edges', 11, [5, 10, 12]); -- → 340.0 ``` -------------------------------- ### Check duckrouting version and Boost build Source: https://github.com/am2222/duckrouting/blob/main/docs/guide/getting-started.md Returns the extension version and the Boost version it was built against. The output shows 'Duckrouting hello, built against Boost 1_89'. ```sql SELECT duckrouting_version('hello'); -- → Duckrouting hello, built against Boost 1_89 ``` -------------------------------- ### Multi-root traversal with duckrouting_prim_bfs Source: https://github.com/am2222/duckrouting/blob/main/docs/functions/spanning-trees.md Shows how to pass a list of roots to walk multiple trees in a single call. Each root is walked separately and reported under its own start_vid. The output shows vertex 6 returns 13 nodes and vertex 13 returns 2 nodes, because a traversal only reaches the root's own component. ```sql SELECT start_vid, count(*) AS nodes FROM duckrouting_prim_bfs( 'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id', [6, 13]) GROUP BY start_vid ORDER BY start_vid; -- → start_vid nodes -- → 6 13 -- → 13 2 ``` -------------------------------- ### Run SQLLogicTests with make test Source: https://github.com/am2222/duckrouting/blob/main/test/README.md Use this command to run the SQLLogicTests. The root makefile contains targets to build and run all tests. ```bash make test ```