pgmp

Multiple Precision Arithmetic extension

Overview

PackageVersionCategoryLicenseLanguage
pgmp1.0.6TYPELGPL-3.0C
IDExtensionBinLibLoadCreateTrustRelocSchema
3700pgmpNoYesNoYesNoYes-
Relatedunit numeral pg_rational uint uint128 seg cube

PIGSTY RPM and DEB packages are aligned at 1.0.6 for PostgreSQL 14 through 18.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.0.61817161514pgmp-
RPMPIGSTY1.0.61817161514pgmp_$v-
DEBPIGSTY1.0.61817161514postgresql-$v-pgmp-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Build

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

pig build pkg pgmp         # build RPM / DEB packages

Install

You can install pgmp 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 pgmp;          # Install for current active PG version
pig ext install -y pgmp -v 18  # PG 18
pig ext install -y pgmp -v 17  # PG 17
pig ext install -y pgmp -v 16  # PG 16
pig ext install -y pgmp -v 15  # PG 15
pig ext install -y pgmp -v 14  # PG 14
dnf install -y pgmp_18       # PG 18
dnf install -y pgmp_17       # PG 17
dnf install -y pgmp_16       # PG 16
dnf install -y pgmp_15       # PG 15
dnf install -y pgmp_14       # PG 14
apt install -y postgresql-18-pgmp   # PG 18
apt install -y postgresql-17-pgmp   # PG 17
apt install -y postgresql-16-pgmp   # PG 16
apt install -y postgresql-15-pgmp   # PG 15
apt install -y postgresql-14-pgmp   # PG 14

Create Extension:

CREATE EXTENSION pgmp;

Usage

Sources:

pgmp exposes GNU MP arithmetic inside PostgreSQL. It adds arbitrary-size integer values through mpz and exact rational values through mpq, together with casts, arithmetic, comparison, aggregate, number-theory, bit, and random-number functions.

Core Workflow

CREATE EXTENSION pgmp;

SELECT '123456789012345678901234567890'::mpz * 2;
SELECT mpq(1::mpz, 3::mpz) + mpq(1::mpz, 6::mpz);
SELECT gcd(48::mpz, 18::mpz);
SELECT nextprime(100000000000000000000::mpz);

mpz is an arbitrary-size integer type, subject to PostgreSQL’s value-size limits. mpq stores a canonical numerator and denominator so fractional arithmetic remains exact until explicitly converted to an approximate type.

Important Objects

  • mpz(text) and casts construct integers in decimal or supported base-prefixed forms.
  • mpq(text) and mpq(mpz, mpz) construct rational values.
  • Both types support ordinary comparisons and btree or hash indexes.
  • Integer helpers include division with explicit rounding modes, powers, roots, primality tests, gcd, lcm, factorials, Fibonacci and Lucas numbers, bit operations, and random-state functions.
  • Rational helpers include numerator and denominator access, inversion, denominator limiting, arithmetic, comparison, and aggregates.
  • gmp_version() and gmp_max_bitcnt() expose library information.

Do not use floating-point input when exact decimal or rational meaning matters; construct values from text, integers, or explicit numerator and denominator values.

Version 1.0.6 Notes

The 1.0.6 distribution adds PostgreSQL 19 build compatibility, sets PostgreSQL 14 as the supported runtime floor in its metadata, and adds missing unsigned-long range checks for the power, Fibonacci, and Lucas-number paths.

The upstream distribution version is 1.0.6, while its tagged pgmp.control currently declares SQL extension version 1.1. Create the extension without forcing a version and inspect the database-reported value before designing an upgrade:

SELECT extversion
FROM pg_extension
WHERE extname = 'pgmp';

pgmp requires the GMP shared library. GMP 4.1 lacks a few functions documented by upstream, including some root, bit, and random-state helpers; use a current GMP release when those objects are required. Large operands can consume substantial backend memory and CPU, so apply statement timeouts and input limits to untrusted arithmetic workloads.


Last Modified: 2026-07-30: extension update 2026-07-30 (7219c44)