Perform unit arithmetic and conversions
masterThe unit type supports standard arithmetic operators and specialized conversion operators.
Arithmetic
You can use +, -, *, /, and ^ to perform calculations between unit values. Multiplication binds tighter than division.
Conversions
@(unit @ text): Converts a unit to a new scale and returns the result as aunittype (including the unit label).@@(unit @@ text): Converts a unit to a new scale and returns the result as adouble precisionnumber.
Note: The units on both sides must have the same dimension.
-- Arithmetic
SELECT '800 m'::unit + '500 m' AS length;
SELECT '9.81 N'::unit / 'kg' AS gravity;
-- Scale conversion (returns unit type)
SELECT '2 MB/min'::unit @ 'GB/d' AS traffic;
-- Scale conversion (returns double precision)
SELECT '2 MB/min'::unit @@ 'GB/d';