Units and Scales in Database Columns

A column name or companion field can specify what stored numeric values measure. Conversions belong at documented interfaces.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a measured time span
  2. Check mixed-unit sources
  3. Convert measurements into one explicit stored unit
  4. Test round trip and precision near conversion thresholds

Trace a measured time span

A numeric value 1500 in a duration column needs a scale. A column called duration_ms or an explicit unit field makes it a meaningful quantity. Values with units explain the conversion to seconds.

Check mixed-unit sources

If an import receives values in milliseconds and seconds, convert both before combining them or store their source units. Typed parser records can retain that context.[1][2]

Convert measurements into one explicit stored unit

Storing height one metre as 100 centimetres and height 0.6 metres as sixty centimetres lets a numeric comparison use one scale. Mixing raw one and sixty without unit markers produces a meaningless order. See values with units.

Source A: 1.0 m → height_cm 100
Source B: 0.6 m → height_cm 60
Comparison in stored units: A > B

Test round trip and precision near conversion thresholds

If centimetres are stored as integers, a height of 1.005 metres needs a specified rounding policy. Document accepted input units even when only one unit is stored. Include a zero and a fractional value.

References

  1. PostgreSQL Global Development Group, Data Definition ↩
  2. PostgreSQL Global Development Group, SQL Language Tutorial ↩