Common SQL Errors

PostgreSQL 22P01 floating_point_exception Explained

August 4, 2025

PostgreSQL raises 22P01 floating_point_exception when a floating-point calculation overflows, underflows, or divides by zero.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is floating_point_exception in PostgreSQL?

floating_point_exception (PostgreSQL error 22P01) signals an invalid floating-point operation, usually divide-by-zero or numeric overflow. Review calculations, add zero-checks, or cast to NUMERIC to resolve the error.

Error Highlights

Typical Error Message

PostgreSQL Error 22P01

Error Type

Runtime Error

Language

PostgreSQL

Symbol

floating_point_exception

Error Code

22P01

SQL State

Explanation

Table of Contents

What is PostgreSQL error 22P01 floating_point_exception?

Error 22P01 appears when PostgreSQL encounters an illegal floating-point operation such as divide-by-zero, overflow, underflow, or invalid cast to floating-point.

The backend halts the current statement to protect data integrity, so the query fails until the arithmetic problem is removed.

What causes this error?

Division by zero in DOUBLE PRECISION or REAL columns is the most frequent cause. PostgreSQL detects the zero divisor and throws 22P01 before completing the calculation.

Overflow or underflow can occur when intermediate results exceed IEEE-754 limits, for example, exponentiation of very large numbers.

Invalid input during implicit casting to float, such as 'NaN' in strict modes, can also trigger the exception.

How to fix floating_point_exception

Add explicit zero checks in WHERE or CASE expressions to avoid divide-by-zero. Use NULLIF or FILTER to skip zero divisors.

Cast to NUMERIC with sufficient precision when working with large magnitudes to avoid overflow. Monitor results with PostgreSQL’s pg_stat_statements.

If the error happens inside PL/pgSQL, wrap the risky expression in BEGIN ... EXCEPTION blocks and handle it gracefully.

Common Scenarios and Solutions

Analytics queries that compute rates suffer when denominator counts are zero. Protect them with NULLIF or COALESCE.

Import jobs that parse CSV strings into FLOAT columns can raise 22P01 when encountering malformed numbers. Validate input or load into TEXT first.

Financial models using exponential growth may overflow. Switch to NUMERIC or scale values down before exponentiation.

Best Practices to Avoid This Error

Always check denominators for zero. Use CHECK constraints to forbid zero in critical columns.

Prefer NUMERIC for money and high-precision data. Reserve floating-point types for scientific workloads where small rounding errors are acceptable.

Add automated tests that run boundary inputs through functions to catch overflow before production.

Related Errors and Solutions

22012 division_by_zero – occurs for integer or NUMERIC division by zero. Fix by adding zero checks.

22003 numeric_value_out_of_range – raised when NUMERIC overflows its scale; increase precision or scale.

42804 datatype_mismatch – appears when implicit cast fails; use explicit CAST to resolve.

Common Causes

Related Errors

FAQs

Does floating_point_exception affect data integrity?

No rows are written or updated when the error occurs, so existing data remains safe.

Why does the error occur only in some environments?

Different hardware or PostgreSQL versions may handle IEEE overflows differently, showing the error only under certain configurations.

Can I disable floating_point_exception checks?

PostgreSQL does not allow disabling; protecting arithmetic integrity is mandatory. Handle or prevent the condition instead.

How does Galaxy help prevent this error?

Galaxy’s inline query linting flags potential zero divisions and suggests NULLIF or FILTER clauses before you run the query.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo