Skip to content

pg_money

Exact currency-aware monetary types, arithmetic, and allocation

Overview

PackageVersionCategoryLicenseLanguage
pg_money0.3.0TYPEMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
3690pg_moneyNoYesNoYesNoYes-

Currency metadata is built in; the currency extension is related, not required.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.3.01817161514pg_money-
RPMPIGSTY0.3.01817161514pg_money_$v-
DEBPIGSTY0.3.01817161514postgresql-$v-pg-money-
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
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u22.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u22.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u24.x86_64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u24.aarch64
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
PIGSTY 0.3.0
u26.x86_64
u26.aarch64

Build

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

pig build pkg pg_money         # build RPM / DEB packages

Install

You can install pg_money 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:

Install
pig install pg_money;          # Install for current active PG version
pig
pig ext install -y pg_money -v 18  # PG 18
pig ext install -y pg_money -v 17  # PG 17
pig ext install -y pg_money -v 16  # PG 16
pig ext install -y pg_money -v 15  # PG 15
pig ext install -y pg_money -v 14  # PG 14
dnf
dnf install -y pg_money_18       # PG 18
dnf install -y pg_money_17       # PG 17
dnf install -y pg_money_16       # PG 16
dnf install -y pg_money_15       # PG 15
dnf install -y pg_money_14       # PG 14
apt
apt install -y postgresql-18-pg-money   # PG 18
apt install -y postgresql-17-pg-money   # PG 17
apt install -y postgresql-16-pg-money   # PG 16
apt install -y postgresql-15-pg-money   # PG 15
apt install -y postgresql-14-pg-money   # PG 14

Create Extension:

CREATE EXTENSION pg_money;

Usage

Sources:

pg_money provides exact currency-aware amounts, arithmetic, rounding, and allocation on PostgreSQL 14–18. Its types are distinct from the locale-sensitive built-in money type.

Core Workflow

CREATE EXTENSION pg_money;
CREATE TABLE invoices (id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
                       total money_with_currency NOT NULL);
INSERT INTO invoices(total) VALUES ('USD 19.95'), (money_make(5.25, 'USD'));
SELECT sum(total), avg(total), money_format(sum(total)) FROM invoices;
SELECT money_split('USD 10.00', 3);
SELECT money_exchange('USD 100', 'EUR', 0.85);

Objects and Semantics

money_with_currency stores a currency with an exact decimal amount; money_minor works with minor-unit amounts. money_make, money_from_minor, and money_minor_make construct values. money_round accepts an explicit rounding mode, and money_split allocates residual units while conserving the total.

Arithmetic and aggregation reject incompatible currencies instead of converting implicitly. Exchange rates are supplied explicitly or read from an application-owned table with money_exchange_at; the extension fetches no market rates. Check rounding and amount bounds at application boundaries.

Operation

The 0.3.0 control file requires superuser installation and allows relocation. No preload is required. Treat exchange-rate tables and mutation privileges separately from read-only arithmetic; caller-supplied SQL data does not establish the correctness or freshness of a rate.

Was this page helpful?