2201FERRORTier 2 — Caution✅ HIGH confidenceinvalid argument for power function
What this means
SQLSTATE 2201F is raised when the POWER() function receives arguments outside its mathematical domain — specifically, a negative base with a non-integer exponent, which produces a complex number that Postgres cannot represent.
Why it happens
- 1Calling POWER(negative_number, fractional_exponent) which is mathematically undefined in real numbers
How to reproduce
Raising a negative number to a fractional power.
SELECT POWER(-2.0, 0.5); -- square root of -2 is imaginaryFix 1: Use ABS to ensure the base is non-negative when the exponent is fractional
When the sign of the base may vary.
SELECT POWER(ABS(value), 0.5) FROM data;Why this works
ABS ensures the base is non-negative, making POWER well-defined for fractional exponents.
Fix 2: Guard with CASE or NULLIF
When a negative base should produce NULL rather than an error.
SELECT CASE WHEN value >= 0 THEN POWER(value, 0.5) ELSE NULL END FROM data;Why this works
The CASE prevents POWER from receiving a negative base.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE for power function domain errors. Stable across versions.
See also
🔗 Related errors
📄 Reference pages