surfacerankingpagerank
Rankingscalar · returns json

PAGERANK

PageRank centrality on an ad-hoc edge list (NetworkX)

Per-row — runs once for each row.

rankingdeterministicjson

Arguments

nametypedescription
edgesJSON
damping(optional)DOUBLE

About

PageRank on an ad-hoc edge table, as a SQL table function. DuckDB has zero native graph operators. This cascade fills the gap by taking a JSON array of edges `[[src, dst, weight?], ...]` and running NetworkX's PageRank algorithm on it in-process, returning one row per node with its score. Uses the `returns_columns` TVF pattern — the registry auto-generates a `pagerank_rows(...)` macro callable with FROM / LATERAL. Usage: -- Compute PageRank from an edge table SELECT * FROM pagerank_rows( (SELECT JSON_GROUP_ARRAY(JSON_ARRAY(src, dst, weight)) FROM edges) ) ORDER BY score DESC LIMIT 20; Edge weights are optional — missing weights default to 1.0. The algorithm treats the graph as directed; symmetrize your edges first if you want an undirected PageRank.

Examples

PageRank on a tiny 4-node directed graph (top node)

SELECT
  node,
  rank
FROM
  pagerank_rows (
    JSON(
      '[["A","B"],["B","C"],["C","A"],["A","C"],["D","A"]]'
    )
  )
ORDER BY
  score DESC
LIMIT
  1;

Nearby rabbit holes

same domain
Climb back to The Looking Glass