DOUBLE PRECISION Data Type in PostgreSQL

Learn how to use PostgreSQL DOUBLE PRECISION (float8) for storing inexact floating-point numbers, including its range, precision limits, special values, and when to use NUMERIC instead.

5 min read · Back to overview

Quick Answer

PostgreSQL DOUBLE PRECISION is an inexact, 8-byte floating-point type implementing IEEE 754. It stores values in the range 1E-307 to 1E+308 with at least 15 decimal digits of precision. Use NUMERIC instead when exact decimal representation is required.

Spin up a Postgres database in 20 seconds with Vela.

Try Vela Sandbox

PostgreSQL’s DOUBLE PRECISION type (also called FLOAT8 or FLOAT) is an inexact, variable-precision numeric type implementing the IEEE 754 double-precision standard. It is best suited for scientific measurements, analytics, and calculations where approximate results are acceptable and query performance matters.

Syntax

column_name DOUBLE PRECISION
column_name FLOAT8   -- alias
column_name FLOAT    -- alias (defaults to double precision)

Key characteristics:

PropertyValue
Storage8 bytes
Range~1E-307 to 1E+308
Precisionat least 15 significant decimal digits
StandardIEEE 754 double precision

Practical Example

Store telemetry readings from IoT sensors in an events table:

CREATE TABLE events (
  id           BIGSERIAL PRIMARY KEY,
  sensor_id    INTEGER NOT NULL,
  occurred_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
  temperature  DOUBLE PRECISION,
  pressure_pa  DOUBLE PRECISION,
  humidity_pct DOUBLE PRECISION
);

INSERT INTO events (sensor_id, temperature, pressure_pa, humidity_pct)
VALUES
  (101, 22.437891, 101325.0, 54.2),
  (101, 22.501234, 101298.5, 53.8),
  (102, 19.883412, 101400.1, 61.0),
  (103, 25.112000, 100980.7, 47.5);

SELECT
  sensor_id,
  AVG(temperature)   AS avg_temp,
  MIN(pressure_pa)   AS min_pressure,
  AVG(humidity_pct)  AS avg_humidity
FROM events
GROUP BY sensor_id;

The Inexact Nature of DOUBLE PRECISION

Because DOUBLE PRECISION uses binary floating-point, some decimal fractions cannot be represented exactly:

SELECT 0.1::double precision + 0.1::double precision + 0.1::double precision;
      ?column?
---------------------
 0.30000000000000004

This is expected IEEE 754 behavior. For financial data, use NUMERIC instead. Avoid equality comparisons on DOUBLE PRECISION columns — use range comparisons:

-- Avoid:
WHERE temperature = 22.5

-- Prefer:
WHERE temperature BETWEEN 22.49 AND 22.51

Special Values

DOUBLE PRECISION supports IEEE 754 special values:

INSERT INTO events (sensor_id, temperature) VALUES (999, 'Infinity');
INSERT INTO events (sensor_id, temperature) VALUES (999, '-Infinity');
INSERT INTO events (sensor_id, temperature) VALUES (999, 'NaN');

-- NaN comparisons: NaN is not equal to itself (IEEE 754)
SELECT 'NaN'::double precision = 'NaN'::double precision; -- false

Testing with Vela

Before deploying an analytical schema that uses DOUBLE PRECISION columns, test aggregation queries on a database branch populated with production-scale data. Accumulated floating-point errors are only apparent at scale, and a branch lets you benchmark SUM, AVG, and STDDEV queries without risk to the live database.

Production Tips

  • Never use DOUBLE PRECISION for monetary values — use NUMERIC to avoid floating-point rounding errors in financial calculations.
  • Avoid equality comparisons on DOUBLE PRECISION values — use range comparisons to account for floating-point imprecision.
  • Use DOUBLE PRECISION for scientific measurements, GPS coordinates, and machine learning feature values where approximate precision is acceptable.
  • Arithmetic on DOUBLE PRECISION is significantly faster than NUMERIC, making it appropriate for analytical workloads on large datasets.
  • Use EXPLAIN ANALYZE to verify that indexes on DOUBLE PRECISION columns are used by range queries as expected.

Continue in PostgreSQL Data Types: REAL.

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

Frequently Asked Questions

What does 'inexact' mean for DOUBLE PRECISION?
Inexact means PostgreSQL cannot represent certain decimal fractions exactly in binary floating-point. For example, 0.1 cannot be stored precisely, so adding three 0.1 values may yield 0.30000000000000004 instead of 0.3. This is a fundamental limitation of IEEE 754, not a PostgreSQL bug.
Does operating on DOUBLE PRECISION columns lock the table?
No. Read and write queries on DOUBLE PRECISION columns take no special locks beyond normal row-level locking. Changing a column type with ALTER TABLE does acquire an ACCESS EXCLUSIVE lock during the rewrite.
What happens to dependent computed columns when I change a DOUBLE PRECISION column?
Changing the column type to a compatible numeric type (e.g. NUMERIC) may require updating generated columns, views, or function signatures that reference it. PostgreSQL will raise errors for incompatible casts; test changes on a branch first.
Can I use special values like Infinity and NaN with DOUBLE PRECISION?
Yes. DOUBLE PRECISION supports 'Infinity', '-Infinity', and 'NaN' as special values. Insert them as quoted string literals: INSERT INTO t(v) VALUES ('Infinity'); They follow IEEE 754 semantics — NaN is not equal to itself, unlike NUMERIC's NaN.
What is the safest way to migrate a DOUBLE PRECISION column to NUMERIC in production?
Add a new NUMERIC column, backfill from the existing DOUBLE PRECISION column with explicit rounding, verify the results, then rename the columns. Test on a Vela branch first to catch any precision loss or overflow that would occur at the boundary.