跳转到主要内容

pg_money

精确的带币种金额类型、算术与金额分摊

pg_money · 精确的带币种金额类型、算术与金额分摊

概览

ID扩展软件包版本类别许可证编程语言
3690pg_moneypg_money0.3.0TYPEMITRust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否
Currency metadata is built in; the currency extension is related, not required.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.3.019 18 17 16 15pg_money-
RPMPIGSTY0.3.019 18 17 16 15pg_money_$v-
DEBPIGSTY0.3.019 18 17 16 15postgresql-$v-pg-money-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el8.aarch64N/APIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el9.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el9.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el10.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
el10.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d12.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d12.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d13.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
d13.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u22.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u22.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u24.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u24.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u26.x86_64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
u26.aarch64PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0PIGSTY 0.3.0
软件包版本平台仓库大小下载
pg_money_190.3.0el9.x86_64pigsty1.2 MiBpg_money_19-0.3.0-2PGSTY.el9.x86_64.rpm
pg_money_190.3.0el9.aarch64pigsty1.1 MiBpg_money_19-0.3.0-2PGSTY.el9.aarch64.rpm
pg_money_190.3.0el10.x86_64pigsty1.2 MiBpg_money_19-0.3.0-2PGSTY.el10.x86_64.rpm
pg_money_190.3.0el10.aarch64pigsty1.2 MiBpg_money_19-0.3.0-2PGSTY.el10.aarch64.rpm
postgresql-19-pg-money0.3.0d12.x86_64pigsty844.7 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~bookworm_amd64.deb
postgresql-19-pg-money0.3.0d12.aarch64pigsty732.9 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~bookworm_arm64.deb
postgresql-19-pg-money0.3.0d13.x86_64pigsty845.3 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~trixie_amd64.deb
postgresql-19-pg-money0.3.0d13.aarch64pigsty733.0 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~trixie_arm64.deb
postgresql-19-pg-money0.3.0u22.x86_64pigsty940.5 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~jammy_amd64.deb
postgresql-19-pg-money0.3.0u22.aarch64pigsty867.4 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~jammy_arm64.deb
postgresql-19-pg-money0.3.0u24.x86_64pigsty929.1 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~noble_amd64.deb
postgresql-19-pg-money0.3.0u24.aarch64pigsty863.0 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~noble_arm64.deb
postgresql-19-pg-money0.3.0u26.x86_64pigsty918.0 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~resolute_amd64.deb
postgresql-19-pg-money0.3.0u26.aarch64pigsty859.0 KiBpostgresql-19-pg-money_0.3.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_money_180.3.0el8.x86_64pigsty1017.7 KiBpg_money_18-0.3.0-1PGSTY.el8.x86_64.rpm
pg_money_180.3.0el8.aarch64pigsty970.7 KiBpg_money_18-0.3.0-1PGSTY.el8.aarch64.rpm
pg_money_180.3.0el9.x86_64pigsty1.2 MiBpg_money_18-0.3.0-2PGSTY.el9.x86_64.rpm
pg_money_180.3.0el9.aarch64pigsty1.1 MiBpg_money_18-0.3.0-2PGSTY.el9.aarch64.rpm
pg_money_180.3.0el10.x86_64pigsty1.2 MiBpg_money_18-0.3.0-2PGSTY.el10.x86_64.rpm
pg_money_180.3.0el10.aarch64pigsty1.1 MiBpg_money_18-0.3.0-2PGSTY.el10.aarch64.rpm
postgresql-18-pg-money0.3.0d12.x86_64pigsty841.7 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~bookworm_amd64.deb
postgresql-18-pg-money0.3.0d12.aarch64pigsty732.0 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~bookworm_arm64.deb
postgresql-18-pg-money0.3.0d13.x86_64pigsty843.5 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~trixie_amd64.deb
postgresql-18-pg-money0.3.0d13.aarch64pigsty732.0 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~trixie_arm64.deb
postgresql-18-pg-money0.3.0u22.x86_64pigsty939.9 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~jammy_amd64.deb
postgresql-18-pg-money0.3.0u22.aarch64pigsty865.4 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~jammy_arm64.deb
postgresql-18-pg-money0.3.0u24.x86_64pigsty926.0 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~noble_amd64.deb
postgresql-18-pg-money0.3.0u24.aarch64pigsty860.2 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~noble_arm64.deb
postgresql-18-pg-money0.3.0u26.x86_64pigsty914.1 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~resolute_amd64.deb
postgresql-18-pg-money0.3.0u26.aarch64pigsty857.8 KiBpostgresql-18-pg-money_0.3.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_money_170.3.0el8.x86_64pigsty1014.9 KiBpg_money_17-0.3.0-1PGSTY.el8.x86_64.rpm
pg_money_170.3.0el8.aarch64pigsty966.9 KiBpg_money_17-0.3.0-1PGSTY.el8.aarch64.rpm
pg_money_170.3.0el9.x86_64pigsty1.2 MiBpg_money_17-0.3.0-2PGSTY.el9.x86_64.rpm
pg_money_170.3.0el9.aarch64pigsty1.1 MiBpg_money_17-0.3.0-2PGSTY.el9.aarch64.rpm
pg_money_170.3.0el10.x86_64pigsty1.2 MiBpg_money_17-0.3.0-2PGSTY.el10.x86_64.rpm
pg_money_170.3.0el10.aarch64pigsty1.1 MiBpg_money_17-0.3.0-2PGSTY.el10.aarch64.rpm
postgresql-17-pg-money0.3.0d12.x86_64pigsty839.4 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~bookworm_amd64.deb
postgresql-17-pg-money0.3.0d12.aarch64pigsty729.7 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~bookworm_arm64.deb
postgresql-17-pg-money0.3.0d13.x86_64pigsty839.4 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~trixie_amd64.deb
postgresql-17-pg-money0.3.0d13.aarch64pigsty729.8 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~trixie_arm64.deb
postgresql-17-pg-money0.3.0u22.x86_64pigsty937.5 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~jammy_amd64.deb
postgresql-17-pg-money0.3.0u22.aarch64pigsty862.9 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~jammy_arm64.deb
postgresql-17-pg-money0.3.0u24.x86_64pigsty922.2 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~noble_amd64.deb
postgresql-17-pg-money0.3.0u24.aarch64pigsty858.8 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~noble_arm64.deb
postgresql-17-pg-money0.3.0u26.x86_64pigsty911.1 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~resolute_amd64.deb
postgresql-17-pg-money0.3.0u26.aarch64pigsty855.6 KiBpostgresql-17-pg-money_0.3.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_money_160.3.0el8.x86_64pigsty1013.7 KiBpg_money_16-0.3.0-1PGSTY.el8.x86_64.rpm
pg_money_160.3.0el8.aarch64pigsty965.8 KiBpg_money_16-0.3.0-1PGSTY.el8.aarch64.rpm
pg_money_160.3.0el9.x86_64pigsty1.2 MiBpg_money_16-0.3.0-2PGSTY.el9.x86_64.rpm
pg_money_160.3.0el9.aarch64pigsty1.1 MiBpg_money_16-0.3.0-2PGSTY.el9.aarch64.rpm
pg_money_160.3.0el10.x86_64pigsty1.2 MiBpg_money_16-0.3.0-2PGSTY.el10.x86_64.rpm
pg_money_160.3.0el10.aarch64pigsty1.1 MiBpg_money_16-0.3.0-2PGSTY.el10.aarch64.rpm
postgresql-16-pg-money0.3.0d12.x86_64pigsty838.1 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~bookworm_amd64.deb
postgresql-16-pg-money0.3.0d12.aarch64pigsty728.7 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~bookworm_arm64.deb
postgresql-16-pg-money0.3.0d13.x86_64pigsty839.1 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~trixie_amd64.deb
postgresql-16-pg-money0.3.0d13.aarch64pigsty730.4 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~trixie_arm64.deb
postgresql-16-pg-money0.3.0u22.x86_64pigsty935.3 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~jammy_amd64.deb
postgresql-16-pg-money0.3.0u22.aarch64pigsty863.2 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~jammy_arm64.deb
postgresql-16-pg-money0.3.0u24.x86_64pigsty921.9 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~noble_amd64.deb
postgresql-16-pg-money0.3.0u24.aarch64pigsty856.0 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~noble_arm64.deb
postgresql-16-pg-money0.3.0u26.x86_64pigsty912.6 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~resolute_amd64.deb
postgresql-16-pg-money0.3.0u26.aarch64pigsty855.1 KiBpostgresql-16-pg-money_0.3.0-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_money_150.3.0el8.x86_64pigsty1005.9 KiBpg_money_15-0.3.0-1PGSTY.el8.x86_64.rpm
pg_money_150.3.0el8.aarch64pigsty955.8 KiBpg_money_15-0.3.0-1PGSTY.el8.aarch64.rpm
pg_money_150.3.0el9.x86_64pigsty1.2 MiBpg_money_15-0.3.0-2PGSTY.el9.x86_64.rpm
pg_money_150.3.0el9.aarch64pigsty1.1 MiBpg_money_15-0.3.0-2PGSTY.el9.aarch64.rpm
pg_money_150.3.0el10.x86_64pigsty1.2 MiBpg_money_15-0.3.0-2PGSTY.el10.x86_64.rpm
pg_money_150.3.0el10.aarch64pigsty1.1 MiBpg_money_15-0.3.0-2PGSTY.el10.aarch64.rpm
postgresql-15-pg-money0.3.0d12.x86_64pigsty836.8 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~bookworm_amd64.deb
postgresql-15-pg-money0.3.0d12.aarch64pigsty726.0 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~bookworm_arm64.deb
postgresql-15-pg-money0.3.0d13.x86_64pigsty836.4 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~trixie_amd64.deb
postgresql-15-pg-money0.3.0d13.aarch64pigsty727.1 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~trixie_arm64.deb
postgresql-15-pg-money0.3.0u22.x86_64pigsty932.0 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~jammy_amd64.deb
postgresql-15-pg-money0.3.0u22.aarch64pigsty859.9 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~jammy_arm64.deb
postgresql-15-pg-money0.3.0u24.x86_64pigsty912.1 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~noble_amd64.deb
postgresql-15-pg-money0.3.0u24.aarch64pigsty853.0 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~noble_arm64.deb
postgresql-15-pg-money0.3.0u26.x86_64pigsty908.8 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~resolute_amd64.deb
postgresql-15-pg-money0.3.0u26.aarch64pigsty849.7 KiBpostgresql-15-pg-money_0.3.0-2PGSTY~resolute_arm64.deb

源码

pig build pkg pg_money;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install pg_money;		# install by package name

pig install pg_money -v 19;   # install for PG 19
pig install pg_money -v 18;   # install for PG 18
pig install pg_money -v 17;   # install for PG 17
pig install pg_money -v 16;   # install for PG 16
pig install pg_money -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pg_money;

用法

来源:

pg_money 在 PostgreSQL 14–18 中提供精确的带币种金额、算术、舍入与分摊功能,其类型独立于受区域设置影响的内置金额类型。

核心工作流

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);

对象与语义

money_with_currency 将币种与精确十进制金额一起存储,money_minor 处理最小货币单位金额。money_make、money_from_minor 和 money_minor_make 用于构造值。money_round 接受明确的舍入模式,money_split 在保持总额不变的前提下分配余数。

算术和聚合会拒绝不兼容币种,不会隐式兑换。汇率须显式提供,或由 money_exchange_at 从应用管理的表中读取;扩展不获取市场行情。应在应用边界检查舍入和金额范围。

运行

0.3.0 控制文件要求超级用户安装,并允许重定位,无需预加载。应将汇率表和修改权限与只读算术区分管理;SQL 输入本身不能证明汇率正确或及时。

表格阅读器