Skip to main content
The unit extension adds support for SI (International System of Units) measurements and conversions in PostgreSQL. Your Nile database arrives with the unit extension already enabled.

Overview

The unit extension provides:
  • Storage and manipulation of SI units and measurements
  • Automatic unit conversion
  • Dimensional analysis
  • Support for SI prefixes (kilo, milli, etc.)
  • Mathematical operations with units

Basic Usage

Creating Unit Values

The unit type accepts values in the format number unit:

Unit Conversions

Units can be converted using the @> operator or the unit_transform function:

Mathematical Operations

The unit extension supports basic mathematical operations while maintaining dimensional correctness:

Working with Measurements in Tables

Error Handling

The unit extension enforces dimensional correctness:

Additional Resources

Unit extension supports a large number of units and conversions, and we’ve only scratched the surface of what it can do. You can find more information in the unit extension repository. The extension uses (among others) the unit definitions from Gnu Units. The unit definition file has comprehensive documentation on the 2400 units it supports.