pg_petgraph
pg_petgraph · In-memory graph algorithms over paired SQL edge arrays
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102466 | pg_petgraph | pg_petgraph | 0.3.0 | TYPE | MIT | Rust |
PostgreSQL · 16, 17, 18
Usage
Sources:
pg_petgraph 0.3.0 provides graph algorithms as ordinary SQL functions over paired edge arrays. The exact Cargo features and CI support PostgreSQL 16, 17 and 18; the README’s older badge is not the current compatibility contract.
Calculate from Edge Arrays
A superuser creates the relocatable Rust/pgrx extension. No preload, restart or other extension dependency is required.
Every edge pairs the values at the same position in sources bigint[] and targets bigint[]. Output retains the original node identifiers. To derive arrays from a table, use the same deterministic ordering in both aggregates.
Function Surface
pagerank returns node scores, with defaults damping = 0.85 and max_iter = 100. scc finds strongly connected components; connected_components finds weakly connected components. betweenness, closeness and eigenvector calculate centrality, and louvain returns community identifiers. dijkstra returns unit-edge distances from a supplied node. toposort returns an ordering or raises an error on a cycle; is_cyclic returns a boolean.
Input and Resource Limits
Graphs are directed, unweighted and rebuilt in memory on every call. Array lengths must match. Isolated nodes cannot be represented without an edge, and a missing start node makes dijkstra fail. In the reviewed implementation, null array elements become node 0 rather than being rejected: filter null endpoints before aggregation. Bound input size and iteration settings yourself; there is no persistent graph store, incremental index or disk-backed traversal.