SQLSTATE 2201F ERROR Class 22: Data Exception

invalid_argument_for_power_function zero raised to a negative power is undefined — 2201F

PostgreSQL error "zero raised to a negative power is undefined" (SQLSTATE 2201F): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Diagnostic Queries

Symptoms

A power() / ^ operation computed 0 raised to a negative exponent, which is undefined (division by zero). PostgreSQL raises SQLSTATE 2201F (invalid_argument_for_power_function).

  • Base is 0 and the exponent is negative.
  • Mathematically equivalent to 1/0.
  • Common with computed base/exponent values.

What the server log shows

ERROR:  zero raised to a negative power is undefined

Why PostgreSQL raises this — what the manual says

As Section 9.3 Mathematical Functions and Operators explains:

Zero raised to a negative power is equivalent to dividing by zero, which is undefined, so power() and the ^ operator reject 0 with a negative exponent.

0 to a negative power equals 1 divided by 0 to a positive power, i.e. division by zero. Since that is undefined, PostgreSQL rejects the operation with 2201F.

Common causes

  • A computed base of 0 with a negative exponent.
  • Unguarded power expressions on variable inputs.
  • Data that allows a zero base.

How to fix it

  1. Guard against a zero base when the exponent can be negative.
  2. Use CASE/NULLIF to handle the zero-base situation.
  3. Validate inputs before the power operation.

Related & next steps

Reference: PostgreSQL 18 Section 9.3 “Mathematical Functions”.

Was this helpful?