PostgreSQL error code
PostgreSQL error 2201F
2201F is the SQLSTATE PostgreSQL reports for invalid argument for power function, in class 22, Data Exception.
| SQLSTATE | 2201F |
|---|---|
| Condition name | invalid_argument_for_power_function |
| Class | 22 — Data Exception |
Reproduce it, then fix it
A negative number raised to a fractional power has no real result, and PostgreSQL raises an error rather than returning NaN. sqrt() of a negative number fails the same way. For cube roots, cbrt() handles negatives. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
SELECT power(-8, 1.0 / 3);
SELECT cbrt(-8);