REAL Data Type in PostgreSQL

Learn how to use the PostgreSQL REAL type for single-precision floating-point storage, including its range, precision limits, aliases, and when to prefer it over DOUBLE PRECISION or NUMERIC.

4 min read · Back to overview

Quick Answer

PostgreSQL REAL is a 4-byte single-precision floating-point type with a range of approximately -3.4E38 to 3.4E38 and about 6 significant decimal digits of precision. Use it to save storage when full double-precision accuracy is not needed.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

The PostgreSQL REAL type (also known as FLOAT4) stores single-precision floating-point numbers using 4 bytes. It is an inexact type — like DOUBLE PRECISION — but trades precision for storage efficiency. Use it for sensor readings, physical measurements, and high-volume time-series data where approximately 6 significant digits is sufficient.

Syntax

column_name REAL
column_name FLOAT4   -- alias, identical behavior

Key characteristics:

PropertyValue
Storage4 bytes
Range~-3.40282347E+38 to 3.40282347E+38
Precision~6 significant decimal digits
StandardIEEE 754 single precision

Practical Example

Store product weight measurements from a factory scale that only reports 5-digit precision:

CREATE TABLE shipments (
  id             BIGSERIAL PRIMARY KEY,
  order_id       INTEGER     NOT NULL,
  dispatched_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
  weight_kg      REAL        NOT NULL,
  volume_liters  REAL        NOT NULL
);

INSERT INTO shipments (order_id, weight_kg, volume_liters)
VALUES
  (1001, 1.25, 3.50),
  (1002, 0.87, 2.10),
  (1003, 4.62, 8.00),
  (1004, 2.30, 5.25);

SELECT
  order_id,
  weight_kg,
  volume_liters,
  weight_kg / volume_liters AS density_kg_per_liter
FROM shipments
ORDER BY order_id;

Observe the characteristic single-precision rounding in the output:

 order_id | weight_kg | volume_liters | density_kg_per_liter
----------+-----------+---------------+----------------------
     1001 |      1.25 |           3.5 |    0.357142865657806
     1002 |      0.87 |           2.1 |    0.414285719394684
     1003 |      4.62 |           8.0 |             0.577500
     1004 |      2.30 |          5.25 |    0.438095241785049

The trailing digits (e.g. 0.357142865657806) are the visible manifestation of single-precision arithmetic.

REAL vs. DOUBLE PRECISION vs. NUMERIC

TypeStoragePrecisionUse case
REAL4 bytes~6 digitsHigh-volume sensors, telemetry
DOUBLE PRECISION8 bytes~15 digitsScientific calculations
NUMERICVariableExactFinancial values, billing

Avoiding Equality Comparisons

Single-precision arithmetic makes equality comparisons unreliable. Use range queries:

-- Avoid: may never match due to rounding
WHERE weight_kg = 1.25

-- Prefer: tolerant range
WHERE weight_kg BETWEEN 1.249 AND 1.251

Testing with Vela

When aggregating large volumes of REAL measurements (cumulative weight totals, average densities), accumulated rounding errors can become visible at scale. Before deploying a reporting query to production, test it on a database branch loaded with production-scale data to quantify the precision loss and decide whether to promote the column to DOUBLE PRECISION.

Production Tips

  • Use REAL when storing large time-series datasets where storage reduction is meaningful and 6 digits of precision is sufficient.
  • Avoid REAL for any financial, billing, or precise scientific computation — use NUMERIC for exact values.
  • Avoid equality comparisons on REAL columns — always use range comparisons to account for floating-point imprecision.
  • Consider DOUBLE PRECISION if you need to aggregate (SUM, AVG) REAL values frequently — accumulated rounding errors are more pronounced in single precision.
  • Inspect the column definition after creation with \d+ table_name to confirm the type is stored as real and not silently promoted.

Continue in PostgreSQL Data Types: Integer.

Related in this section: Boolean · CHAR, VARCHAR, and TEXT · NUMERIC

Frequently Asked Questions

What is the difference between REAL and DOUBLE PRECISION in PostgreSQL?
REAL uses 4 bytes and provides about 6 significant decimal digits. DOUBLE PRECISION uses 8 bytes and provides at least 15 significant decimal digits. Both are inexact floating-point types, but DOUBLE PRECISION has a much wider range and higher precision. Choose REAL when storage efficiency matters and reduced precision is acceptable.
Does filtering on a REAL column lock the table?
No. SELECT queries on REAL columns use no exclusive locks. Only DDL operations such as ALTER TABLE to change the column type acquire an ACCESS EXCLUSIVE lock.
What happens to dependent views when I change a REAL column to DOUBLE PRECISION?
Views that reference the REAL column continue to work after altering the type to DOUBLE PRECISION because the cast is implicit. If any view applies an explicit cast to REAL or FLOAT4, those casts should be reviewed after the migration.
Is REAL suitable for financial calculations?
No. REAL is an inexact type with only ~6 significant digits, making it unsuitable for monetary amounts or any value requiring exact decimal arithmetic. Use NUMERIC for financial data.
What is the safest way to use REAL for a high-volume time-series table in production?
Define the column as REAL, add an index on the timestamp column for range queries, and avoid equality comparisons on the REAL values. Test aggregation queries on a Vela branch populated with representative data to verify that accumulated rounding errors are within acceptable bounds.