Skip to main content

real

Learning Focus

Use this lesson to understand PostgreSQL real (single-precision floating point) and where approximate math is acceptable.

real Overview

  • Storage: 4 bytes
  • Approximate floating point
  • Best for: scientific/measurement data where small rounding errors are acceptable

Example

CREATE TABLE sensors (
sensor_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
temperature_c real NOT NULL,
recorded_at timestamptz NOT NULL DEFAULT now()
);

Common Pitfalls

PitfallConsequencePrevention
Using real for currencyRounding errorsUse numeric(12,2)

What's Next