Menu

PostgreSQL REAL and DOUBLE PRECISION Types

Compare PostgreSQL REAL, DOUBLE PRECISION, and FLOAT. See their storage, precision, ranges, and why these types store approximate values.

PostgreSQL REAL and DOUBLE PRECISION store approximate binary floating-point values. Use them for measurements and scientific calculations when a small rounding difference is acceptable. Use NUMERIC for exact decimal values such as prices, and integer types for whole-number counts.

Type Alias Storage Decimal precision Approximate positive magnitude
REAL FLOAT4 4 bytes at least 6 significant digits 1E-37 to 1E+37
DOUBLE PRECISION FLOAT8, FLOAT 8 bytes at least 15 significant digits 1E-307 to 1E+308

The table shows positive magnitudes. Corresponding negative values are also representable. Values too large or too small for the type cause an error; a value too close to zero to remain distinct from zero can also cause an underflow error.

FLOAT(p) selects a type by its binary precision p: values from 1 to 24 select REAL, and 25 to 53 select DOUBLE PRECISION. FLOAT without a precision is DOUBLE PRECISION.

Declare a floating-point column

Use REAL when single precision is sufficient, or DOUBLE PRECISION when you need more range and precision:

CREATE TABLE sensor_readings (
    reading_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    temperature real NOT NULL,
    pressure double precision NOT NULL
);

Floating-point values are approximate

Binary floating-point cannot represent many decimal fractions exactly. For example, multiplying a binary approximation of 0.1 by 3 can produce a small visible difference from exact decimal arithmetic:

SELECT
    0.1::numeric * 3 AS exact_decimal,
    0.1::double precision * 3 AS approximate_float;
 exact_decimal | approximate_float
---------------+-------------------
 0.3           | 0.30000000000000004

Avoid relying on exact equality for floating-point calculations. When comparing measured values, choose an application-appropriate tolerance. PostgreSQL REAL and DOUBLE PRECISION use IEEE 754 binary floating-point where supported by the platform.

Further reading

Advertisement