pg_algorithms
C extension that adds example algorithm functions, including bubble sort and quicksort for integer arrays.
pg_algorithms · C extension that adds example algorithm functions, including bubble sort and quicksort for integer arrays.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100580 | pg_algorithms | pg_algorithms | 1.0 | FUNC | MIT | C |
Usage
Sources:
pg_algorithms 1.0 exposes demonstration implementations of bubble sort and quicksort for integer arrays. Upstream describes it as a pet project; use it for learning or small experiments, not as a production sorting primitive.
Core Workflow
Function Index
bubble_sort(integer[])returns an ascending one-dimensional integer array using bubble sort.quick_sort(integer[])returns an ascending one-dimensional integer array using a recursive first-element-pivot quicksort.- Both functions are strict and stable. The SQL surface exposes integer arrays only.
Caveats
- NULL array elements and multidimensional arrays are rejected by the C implementation.
- Bubble sort has quadratic runtime. The chosen quicksort pivot also reaches quadratic runtime and deep recursion on already ordered or adversarial input.
- Prefer PostgreSQL’s native ORDER BY for real workloads; it has mature memory, disk-spill, collation, and planner integration.