REAL (4-byte single-precision float)
Last updated: 2026-11-04
REAL (4-byte single-precision float)
REAL is PostgreSQL's single-precision floating-point type, the counterpart of C's float, occupying 4 bytes with about 24 mantissa bits, roughly 6 to 7 decimal digits of significance. It suits scientific measurements, sensor readings and ratios where "close enough" is acceptable, and it is both half the size and faster than DOUBLE PRECISION. It cannot represent decimals such as 0.1, 0.2 or 0.3 exactly, so it must never hold money.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
REAL | FLOAT4 —— single-precision float, 4 bytes, about 6 to 7 decimal digits of significance
Returns:Holds a 4-byte single-precision float. Every decimal literal is first converted to its nearest binary approximation, so summing many rows accumulates error and equality comparisons are unreliable.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | ratio | col_type | exact_equal
----+------------+----------+-------------
1 | 0.1 | real | t
2 | 0.33333334 | real | t
📌 Key Points
- 0.1::real + 0.2::real comes out exactly equal to 0.3::real, so the equality holds for REAL: with only about 7 significant digits, binary rounding absorbs the error. Switch to DOUBLE PRECISION and the same comparison returns false.
- 1::real / 3::real yields 0.33333334, only about 8 significant digits; NUMERIC would give as many decimals as you ask for.
- Trade-off: REAL saves space and runs fast, which suits tolerance-based comparisons (via BETWEEN or an absolute difference), but it is never acceptable for amounts or tax values that must be exact.