unit
SI units extension
Repository
df7cb/postgresql-unit
https://github.com/df7cb/postgresql-unit
Source
postgresql-unit-7.10.tar.gz
postgresql-unit-7.10.tar.gz
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 3550 | unit | No | Yes | No | Yes | No | No | - |
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 7.10 | 1817161514 | pgunit | plpgsql |
| RPM | PGDG | 7.10 | 1817161514 | postgresql-unit_$v | - |
| DEB | PGDG | 7.10 | 1817161514 | postgresql-$v-unit | - |
Install
You can install pgunit directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Install
pig
dnf
apt
Create Extension:
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
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)