PG
PRO
2201FERRORTier 2 — Caution✅ HIGH confidence

invalid argument for power function

Category: Data ExceptionVersions: All Postgres versions

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

  1. 1Calling POWER(negative_number, fractional_exponent) which is mathematically undefined in real numbers

How to reproduce

Raising a negative number to a fractional power.

trigger — this will ERROR
SELECT POWER(-2.0, 0.5); -- square root of -2 is imaginary
ERROR: a negative number raised to a non-integer power is not allowed

Fix 1: Use ABS to ensure the base is non-negative when the exponent is fractional

When the sign of the base may vary.

fix
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.

fix
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

📄 Reference pages

Mathematical FunctionsPOWER
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →