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.

Kindtype
Example LanguageSQL

📝 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

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow much do REAL and DOUBLE PRECISION differ?
AREAL takes 4 bytes with about 6 to 7 decimal digits; DOUBLE PRECISION takes 8 bytes with roughly 15 to 16. For most applications DOUBLE PRECISION is the safer default, and REAL is only worth it when memory or storage is genuinely tight.
QWhy does 0.1 + 0.2 equal 0.3 for REAL?
ABecause 0.1 and 0.2 are both approximations in binary, their combined error is on the order of 1e-8, which is about the same size as the gap between adjacent float4 values, so rounding collapses both sides onto the same float4. With float8 the error survives, it is simply hidden by the much finer spacing.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏