22P01ERRORTier 2 — Caution✅ HIGH confidencefloating point exception
What this means
SQLSTATE 22P01 is a Postgres-specific error raised when a floating-point arithmetic operation produces an exception, such as overflow to infinity or an invalid operation (e.g., 0.0/0.0 producing NaN in a strict context).
Why it happens
- 1Floating-point division by zero (produces infinity in IEEE 754; some contexts treat this as an error)
- 2Floating-point operations producing Inf or NaN that are rejected by the calling context
How to reproduce
FP operation producing an exceptional result.
SELECT 1.0::float / 0.0::float; -- produces Infinity in Postgres (not 22P01)
-- 22P01 appears in contexts that reject Inf/NaNFix 1: Check for zero denominators before FP division
When floating-point division may involve zero.
SELECT CASE WHEN denom = 0.0 THEN NULL ELSE num / denom END FROM data;Why this works
A CASE guard prevents the division from occurring when the denominator is zero.
Fix 2: Filter Inf and NaN results
When FP results must be finite.
SELECT CASE WHEN result IS NOT NULL AND result = result AND ABS(result) < 'Inf'::float
THEN result ELSE NULL END FROM computed;Why this works
Checking result = result (NaN != NaN) and ABS(result) < Inf filters out both NaN and infinity.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception (Postgres-specific)
Confidence assessment
✅ HIGH confidence
Postgres-specific extension. Behaviour depends on platform FP library; generally stable.
See also
📄 Reference pages