unit
SI units extension
pgunit : SI units extension
Overview
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 7.10 |
18 17 16 15 14 | pgunit |
plpgsql |
| 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 / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| el8.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| el9.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| el9.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| el10.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| el10.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| d12.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| d12.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| d13.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| d13.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| u22.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| u22.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| u24.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| u24.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| u26.x86_64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
| u26.aarch64 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 | PIGSTY 7.10 |
Source
github.com/df7cb/postgresql-unit
postgresql-unit-7.10.tar.gz
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
Usage
The unit extension provides a data type for SI units, enabling dimensional analysis and unit conversion directly in SQL.
Base Units
meter (m), kilogram (kg), second (s), ampere (A), kelvin (K), mole (mol), candela (cd), byte (B).
Operators
| Operator | Description | Example |
|---|---|---|
+, - |
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
Unit Conversion
Range Type
Configuration
unit.byte_output_iec: Binary prefixes (Ki, Mi, Gi)unit.output_base_units: Show only base unitsunit.time_output_custom: Format times using minutes/hours/daysunit.output_superscript: Unicode superscript exponents