unit

pgunit : SI units extension

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
3520
unit
pgunit
7.10
TYPE
GPL-2.0
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
Requires
plpgsql
See Also
pgmp
numeral
prefix
semver
pgpdf
pglite_fusion
md5hash
asn1oid

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
7.10
18
17
16
15
14
pgunitplpgsql
RPM
PGDG
7.10
18
17
16
15
14
postgresql-unit_$v-
DEB
PGDG
7.10
18
17
16
15
14
postgresql-$v-unit-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
el8.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
el9.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
el9.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
el10.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
el10.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
d12.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
d12.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
d13.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
d13.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
u22.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
u22.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
u24.x86_64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
u24.aarch64
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PGDG 7.10
PackageVersionOSORGSIZEFile URL
postgresql-unit_177.10el8.x86_64pgdg128.4 KiBpostgresql-unit_17-7.10-1PGDG.rhel8.x86_64.rpm
postgresql-unit_177.9el8.x86_64pgdg90.6 KiBpostgresql-unit_17-7.9-1PGDG.rhel8.x86_64.rpm
postgresql-unit_177.10el8.aarch64pgdg127.0 KiBpostgresql-unit_17-7.10-1PGDG.rhel8.aarch64.rpm
postgresql-unit_177.9el8.aarch64pgdg89.2 KiBpostgresql-unit_17-7.9-1PGDG.rhel8.aarch64.rpm
postgresql-unit_177.10el9.x86_64pgdg123.4 KiBpostgresql-unit_17-7.10-1PGDG.rhel9.x86_64.rpm
postgresql-unit_177.9el9.x86_64pgdg88.5 KiBpostgresql-unit_17-7.9-1PGDG.rhel9.x86_64.rpm
postgresql-unit_177.10el9.aarch64pgdg122.4 KiBpostgresql-unit_17-7.10-1PGDG.rhel9.aarch64.rpm
postgresql-unit_177.9el9.aarch64pgdg87.4 KiBpostgresql-unit_17-7.9-1PGDG.rhel9.aarch64.rpm
postgresql-unit_177.10el10.x86_64pgdg123.9 KiBpostgresql-unit_17-7.10-3PGDG.rhel10.x86_64.rpm
postgresql-unit_177.10el10.aarch64pgdg123.2 KiBpostgresql-unit_17-7.10-3PGDG.rhel10.aarch64.rpm
postgresql-17-unit7.10d12.x86_64pgdg158.5 KiBpostgresql-17-unit_7.10-2.pgdg12+1_amd64.deb
postgresql-17-unit7.10d12.aarch64pgdg157.1 KiBpostgresql-17-unit_7.10-2.pgdg12+1_arm64.deb
postgresql-17-unit7.10d13.x86_64pgdg158.5 KiBpostgresql-17-unit_7.10-2.pgdg13+1_amd64.deb
postgresql-17-unit7.10d13.aarch64pgdg157.2 KiBpostgresql-17-unit_7.10-2.pgdg13+1_arm64.deb
postgresql-17-unit7.10u22.x86_64pgdg164.3 KiBpostgresql-17-unit_7.10-2.pgdg22.04+1_amd64.deb
postgresql-17-unit7.10u22.aarch64pgdg162.7 KiBpostgresql-17-unit_7.10-2.pgdg22.04+1_arm64.deb
postgresql-17-unit7.10u24.x86_64pgdg158.5 KiBpostgresql-17-unit_7.10-2.pgdg24.04+1_amd64.deb
postgresql-17-unit7.10u24.aarch64pgdg157.0 KiBpostgresql-17-unit_7.10-2.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
postgresql-unit_167.10el8.x86_64pgdg128.4 KiBpostgresql-unit_16-7.10-1PGDG.rhel8.x86_64.rpm
postgresql-unit_167.9el8.x86_64pgdg90.6 KiBpostgresql-unit_16-7.9-1PGDG.rhel8.x86_64.rpm
postgresql-unit_167.7el8.x86_64pigsty90.2 KiBpostgresql-unit_16-7.7-1PIGSTY.el8.x86_64.rpm
postgresql-unit_167.10el8.aarch64pgdg127.0 KiBpostgresql-unit_16-7.10-1PGDG.rhel8.aarch64.rpm
postgresql-unit_167.9el8.aarch64pgdg89.2 KiBpostgresql-unit_16-7.9-1PGDG.rhel8.aarch64.rpm
postgresql-unit_167.10el9.x86_64pgdg123.4 KiBpostgresql-unit_16-7.10-1PGDG.rhel9.x86_64.rpm
postgresql-unit_167.9el9.x86_64pgdg88.5 KiBpostgresql-unit_16-7.9-1PGDG.rhel9.x86_64.rpm
postgresql-unit_167.7el9.x86_64pigsty88.6 KiBpostgresql-unit_16-7.7-1PIGSTY.el9.x86_64.rpm
postgresql-unit_167.10el9.aarch64pgdg122.4 KiBpostgresql-unit_16-7.10-1PGDG.rhel9.aarch64.rpm
postgresql-unit_167.9el9.aarch64pgdg87.4 KiBpostgresql-unit_16-7.9-1PGDG.rhel9.aarch64.rpm
postgresql-unit_167.10el10.x86_64pgdg123.9 KiBpostgresql-unit_16-7.10-3PGDG.rhel10.x86_64.rpm
postgresql-unit_167.10el10.aarch64pgdg123.2 KiBpostgresql-unit_16-7.10-3PGDG.rhel10.aarch64.rpm
postgresql-16-unit7.10d12.x86_64pgdg158.5 KiBpostgresql-16-unit_7.10-2.pgdg12+1_amd64.deb
postgresql-16-unit7.10d12.aarch64pgdg157.0 KiBpostgresql-16-unit_7.10-2.pgdg12+1_arm64.deb
postgresql-16-unit7.10d13.x86_64pgdg158.5 KiBpostgresql-16-unit_7.10-2.pgdg13+1_amd64.deb
postgresql-16-unit7.10d13.aarch64pgdg157.1 KiBpostgresql-16-unit_7.10-2.pgdg13+1_arm64.deb
postgresql-16-unit7.10u22.x86_64pgdg164.3 KiBpostgresql-16-unit_7.10-2.pgdg22.04+1_amd64.deb
postgresql-16-unit7.10u22.aarch64pgdg162.6 KiBpostgresql-16-unit_7.10-2.pgdg22.04+1_arm64.deb
postgresql-16-unit7.10u24.x86_64pgdg158.6 KiBpostgresql-16-unit_7.10-2.pgdg24.04+1_amd64.deb
postgresql-16-unit7.10u24.aarch64pgdg157.1 KiBpostgresql-16-unit_7.10-2.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
postgresql-unit_157.10el8.x86_64pgdg129.3 KiBpostgresql-unit_15-7.10-1PGDG.rhel8.x86_64.rpm
postgresql-unit_157.9el8.x86_64pgdg91.5 KiBpostgresql-unit_15-7.9-1PGDG.rhel8.x86_64.rpm
postgresql-unit_157.4el8.x86_64pgdg134.9 KiBpostgresql-unit_15-7.4-1.rhel8.x86_64.rpm
postgresql-unit_157.10el8.aarch64pgdg127.7 KiBpostgresql-unit_15-7.10-1PGDG.rhel8.aarch64.rpm
postgresql-unit_157.9el8.aarch64pgdg89.9 KiBpostgresql-unit_15-7.9-1PGDG.rhel8.aarch64.rpm
postgresql-unit_157.4el8.aarch64pgdg133.5 KiBpostgresql-unit_15-7.4-1.rhel8.aarch64.rpm
postgresql-unit_157.10el9.x86_64pgdg125.1 KiBpostgresql-unit_15-7.10-1PGDG.rhel9.x86_64.rpm
postgresql-unit_157.9el9.x86_64pgdg90.2 KiBpostgresql-unit_15-7.9-1PGDG.rhel9.x86_64.rpm
postgresql-unit_157.4el9.x86_64pgdg136.3 KiBpostgresql-unit_15-7.4-1.rhel9.x86_64.rpm
postgresql-unit_157.10el9.aarch64pgdg124.1 KiBpostgresql-unit_15-7.10-1PGDG.rhel9.aarch64.rpm
postgresql-unit_157.9el9.aarch64pgdg89.3 KiBpostgresql-unit_15-7.9-1PGDG.rhel9.aarch64.rpm
postgresql-unit_157.4el9.aarch64pgdg134.9 KiBpostgresql-unit_15-7.4-1.rhel9.aarch64.rpm
postgresql-unit_157.10el10.x86_64pgdg125.8 KiBpostgresql-unit_15-7.10-3PGDG.rhel10.x86_64.rpm
postgresql-unit_157.10el10.aarch64pgdg124.7 KiBpostgresql-unit_15-7.10-3PGDG.rhel10.aarch64.rpm
postgresql-15-unit7.10d12.x86_64pgdg159.7 KiBpostgresql-15-unit_7.10-2.pgdg12+1_amd64.deb
postgresql-15-unit7.10d12.aarch64pgdg157.7 KiBpostgresql-15-unit_7.10-2.pgdg12+1_arm64.deb
postgresql-15-unit7.10d13.x86_64pgdg159.6 KiBpostgresql-15-unit_7.10-2.pgdg13+1_amd64.deb
postgresql-15-unit7.10d13.aarch64pgdg157.9 KiBpostgresql-15-unit_7.10-2.pgdg13+1_arm64.deb
postgresql-15-unit7.10u22.x86_64pgdg165.5 KiBpostgresql-15-unit_7.10-2.pgdg22.04+1_amd64.deb
postgresql-15-unit7.10u22.aarch64pgdg163.8 KiBpostgresql-15-unit_7.10-2.pgdg22.04+1_arm64.deb
postgresql-15-unit7.10u24.x86_64pgdg159.8 KiBpostgresql-15-unit_7.10-2.pgdg24.04+1_amd64.deb
postgresql-15-unit7.10u24.aarch64pgdg158.1 KiBpostgresql-15-unit_7.10-2.pgdg24.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
postgresql-unit_147.10el8.x86_64pgdg129.3 KiBpostgresql-unit_14-7.10-1PGDG.rhel8.x86_64.rpm
postgresql-unit_147.9el8.x86_64pgdg91.5 KiBpostgresql-unit_14-7.9-1PGDG.rhel8.x86_64.rpm
postgresql-unit_147.4el8.x86_64pgdg134.9 KiBpostgresql-unit_14-7.4-1.rhel8.x86_64.rpm
postgresql-unit_147.10el8.aarch64pgdg127.7 KiBpostgresql-unit_14-7.10-1PGDG.rhel8.aarch64.rpm
postgresql-unit_147.9el8.aarch64pgdg90.0 KiBpostgresql-unit_14-7.9-1PGDG.rhel8.aarch64.rpm
postgresql-unit_147.4el8.aarch64pgdg133.4 KiBpostgresql-unit_14-7.4-1.rhel8.aarch64.rpm
postgresql-unit_147.10el9.x86_64pgdg125.0 KiBpostgresql-unit_14-7.10-1PGDG.rhel9.x86_64.rpm
postgresql-unit_147.9el9.x86_64pgdg90.2 KiBpostgresql-unit_14-7.9-1PGDG.rhel9.x86_64.rpm
postgresql-unit_147.4el9.x86_64pgdg136.2 KiBpostgresql-unit_14-7.4-1.rhel9.x86_64.rpm
postgresql-unit_147.10el9.aarch64pgdg124.1 KiBpostgresql-unit_14-7.10-1PGDG.rhel9.aarch64.rpm
postgresql-unit_147.9el9.aarch64pgdg89.2 KiBpostgresql-unit_14-7.9-1PGDG.rhel9.aarch64.rpm
postgresql-unit_147.4el9.aarch64pgdg134.9 KiBpostgresql-unit_14-7.4-1.rhel9.aarch64.rpm
postgresql-unit_147.10el10.x86_64pgdg125.8 KiBpostgresql-unit_14-7.10-3PGDG.rhel10.x86_64.rpm
postgresql-unit_147.10el10.aarch64pgdg124.7 KiBpostgresql-unit_14-7.10-3PGDG.rhel10.aarch64.rpm
postgresql-14-unit7.10d12.x86_64pgdg159.6 KiBpostgresql-14-unit_7.10-2.pgdg12+1_amd64.deb
postgresql-14-unit7.10d12.aarch64pgdg157.6 KiBpostgresql-14-unit_7.10-2.pgdg12+1_arm64.deb
postgresql-14-unit7.10d13.x86_64pgdg159.3 KiBpostgresql-14-unit_7.10-2.pgdg13+1_amd64.deb
postgresql-14-unit7.10d13.aarch64pgdg157.9 KiBpostgresql-14-unit_7.10-2.pgdg13+1_arm64.deb
postgresql-14-unit7.10u22.x86_64pgdg165.5 KiBpostgresql-14-unit_7.10-2.pgdg22.04+1_amd64.deb
postgresql-14-unit7.10u22.aarch64pgdg163.7 KiBpostgresql-14-unit_7.10-2.pgdg22.04+1_arm64.deb
postgresql-14-unit7.10u24.x86_64pgdg159.8 KiBpostgresql-14-unit_7.10-2.pgdg24.04+1_amd64.deb
postgresql-14-unit7.10u24.aarch64pgdg158.1 KiBpostgresql-14-unit_7.10-2.pgdg24.04+1_arm64.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

pig install pgunit;		# install via package name, for the active PG version
pig install unit;		# install by extension name, for the current active PG version

pig install unit -v 18;   # install for PG 18
pig install unit -v 17;   # install for PG 17
pig install unit -v 16;   # install for PG 16
pig install unit -v 15;   # install for PG 15
pig install unit -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION unit CASCADE; -- requires plpgsql

Usage

unit: SI unit data type for PostgreSQL

The unit extension provides a data type for SI units, enabling dimensional analysis and unit conversion directly in SQL.

CREATE EXTENSION unit;

SELECT '9.81 m/s^2'::unit;
SELECT '120 km/h'::unit @ 'm/s' AS velocity;  -- 33.3333333333333 m/s

Base Units

meter (m), kilogram (kg), second (s), ampere (A), kelvin (K), mole (mol), candela (cd), byte (B).

Operators

OperatorDescriptionExample
+, -Add/subtract (same dimensions)'1 m'::unit + '50 cm'::unit
*, /Multiply/divide'5 kg'::unit * '9.81 m/s^2'::unit
^Exponentiation by integer'2 m'::unit ^ 3
@Convert to unit (returns unit)'2 MB/min'::unit @ 'GB/d'
@@Convert to unit (returns double precision)'1 km'::unit @@ 'm'

Functions

Mathematical: sqrt(), exp(), ln(), log2(), cbrt(), asin(), tan(), etc.

Aggregates: sum(unit), avg(unit), min(unit), max(unit), stddev(), variance().

Input Formats

SELECT '3|4 m'::unit;            -- fractions: 0.75 m
SELECT '10:05:30 s'::unit;       -- time format: 36330 s
SELECT 'm⁻²'::unit;              -- Unicode superscripts

Unit Conversion

SELECT '2 MB/min'::unit @ 'GB/d';       -- 2.88 GB/d
SELECT '1 hl'::unit @ '0.5 l';          -- 200 * 0.5 l
SELECT '100 degC'::unit @ 'degF';        -- Fahrenheit conversion

Range Type

SELECT unitrange('earthradius_polar', 'earthradius_equatorial');

Configuration

  • unit.byte_output_iec: Binary prefixes (Ki, Mi, Gi)
  • unit.output_base_units: Show only base units
  • unit.time_output_custom: Format times using minutes/hours/days
  • unit.output_superscript: Unicode superscript exponents
Last updated on