onesparse

Sparse linear algebra and graph extension for PostgreSQL 18

Overview

PackageVersionCategoryLicenseLanguage
one_sparse1.0.0FEATApache-2.0C
IDExtensionBinLibLoadCreateTrustRelocSchema
2620onesparseNoYesNoYesNoNoonesparse
Relatedage pgrouting postgis

PG18 only; upstream release v1.0.0 ships extension SQL version 0.1.0

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.0.01817161514one_sparse-
RPMPIGSTY1.0.01817161514onesparse_$vgraphblas, lagraph
DEBPIGSTY1.0.01817161514postgresql-$v-onesparselibgraphblas10, liblagraph1, liblagraphx1
OS / PGPG18PG17PG16PG15PG14
el8.x86_64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
el8.aarch64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
el9.x86_64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
el9.aarch64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
el10.x86_64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
el10.aarch64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
d12.x86_64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
d12.aarch64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
d13.x86_64PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
d13.aarch64
PIGSTY 1.0.0
PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
u22.x86_64
PIGSTY 1.0.0
PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
u22.aarch64
PIGSTY 1.0.0
PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
u24.x86_64
PIGSTY 1.0.0
PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS
u24.aarch64
PIGSTY 1.0.0
PIGSTY MISSPIGSTY MISSPIGSTY MISSPIGSTY MISS

Build

You can build the RPM / DEB packages for one_sparse using pig build:

pig build pkg one_sparse         # build RPM / DEB packages

Install

You can install one_sparse directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install one_sparse;          # Install for current active PG version
pig ext install -y one_sparse -v 18  # PG 18
dnf install -y onesparse_18       # PG 18
apt install -y postgresql-18-onesparse   # PG 18

Create Extension:

CREATE EXTENSION onesparse;

Usage

Sources: homepage, release v1.0.0, control file at v1.0.0, intro docs, matrix docs, vector docs, algorithm examples

OneSparse is a PostgreSQL extension that binds SuiteSparse:GraphBLAS into Postgres and exposes sparse linear algebra and graph algorithms as new types, functions, and operators. The docs treat matrix as the core type, with vector and scalar built on top of the same model. The v1.0.0 release exists, while the extension control file at that tag still declares SQL default_version = '0.1.0'.

Core Setup

CREATE EXTENSION onesparse;
SET search_path TO public,onesparse;

SELECT 'int32'::matrix;
SELECT 'int32'::vector;
SELECT 'int32:42'::scalar;

The docs site organizes the API around matrix, vector, and scalar, with interactive examples using casts and constructors.

Matrix and Vector

The matrix page shows common operations such as construction, print(), draw(), assignment, extraction, cast_to(), resize, and aggregation. The vector page documents the matching vector API including nvals(), size(), eadd(), emult(), reduce_scalar(), choose(), and apply().

SELECT print('int32(4:4)'::matrix);
SELECT draw('int32(4:4)[1:2:1 2:3:2 3:1:3]'::matrix);
SELECT eadd('int32[0:1 1:2 2:3]'::vector, 'int32[0:1 1:2 2:3]'::vector, 'plus_int32');
SELECT reduce_scalar('int32[0:1 1:2 2:3]'::vector, 'plus_monoid_int32');

Graph Algorithms

The examples page uses Matrix Market input and graph visualization with draw(...). The documented graph algorithms include:

  • bfs(graph, 1) for level and parent BFS
  • sssp(cast_to(graph, 'int32'), 1::bigint, 1) for single-source shortest path
  • pagerank(graph) for ranking vertices by link structure
  • triangle_centrality(graph) for triangle-based centrality
  • betweenness(graph, ARRAY[...]) and square_clustering(graph) for additional graph analysis

Representative example from the docs:

SELECT draw(triu(graph), (SELECT level FROM bfs(graph, 1)), false, false, true, 0.5)
FROM karate;

The same guide shows loading a graph with mmread('/home/postgres/onesparse/demo/karate.mtx').


Last Modified 2026-04-19: update extension stub docs (9f178c3)