pgmp

Multiple Precision Arithmetic extension

Overview

PackageVersionCategoryLicenseLanguage
pgmp1.0.5TYPELGPL-3.0C
IDExtensionBinLibLoadCreateTrustRelocSchema
3700pgmpNoYesNoYesNoYes-
Relatednumeral unit pguecc pgcrypto prefix semver pgpdf pglite_fusion

missing pg14 on el pgdg repo

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.0.51817161514pgmp-
RPMPGDG1.0.51817161514pgmp_$v-
DEBPGDG1.0.51817161514postgresql-$v-pgmp-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64PGDG MISS
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PGDG 1.0.5
PGDG 1.0.5
PGDG 1.0.5
PGDG 1.0.5
PGDG 1.0.5
d13.x86_64
d13.aarch64
PGDG 1.0.5
PGDG 1.0.5
PGDG 1.0.5
PGDG 1.0.5
PGDG 1.0.5
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

Install

You can install pgmp directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG 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

pgmp: multiple precision arithmetic (GMP) for PostgreSQL

The pgmp extension integrates the GNU Multiple Precision (GMP) library into PostgreSQL, providing arbitrary-precision integer and rational number types.

CREATE EXTENSION pgmp;

Data Types

  • mpz: Arbitrary-size integers, limited only by PostgreSQL’s 1GB varlena maximum
  • mpq: Arbitrary-precision rational numbers for exact fractional arithmetic

Basic Usage

-- Arbitrary precision integers
SELECT '123456789012345678901234567890'::mpz * 2;

-- Exact rational arithmetic (no rounding)
SELECT '1'::mpq / '3'::mpq;  -- 1/3

-- Mixed arithmetic with native PostgreSQL types
SELECT 42::mpz + '100'::mpz;

Operators

Standard arithmetic operators (+, -, *, /, %) and comparison operators (=, <>, <, >, <=, >=) are supported for both mpz and mpq.

Functions

The extension exposes all GMP library functions for these types, including:

  • Prime number functions
  • Random number generation
  • Factorization
  • GCD, LCM, and other number theory functions

Index Support

Both mpz and mpq support btree and hash indexes for efficient queries and sorting.

Full documentation: https://www.varrazzo.com/pgmp/


Last Modified 2026-03-12: add pg extension catalog (95749bf)