select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

invalid_argument_for_logarithm

SQLSTATE
2201E
Condition name
invalid_argument_for_logarithm
Class
Data Exception
Source macro
ERRCODE_INVALID_ARGUMENT_FOR_LOG
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>2201E</h1>

At a glance

Logarithm functions reject zero and negative inputs at their defined-domain guards. Fixed float paths report cannot take logarithm of zero or cannot take logarithm of a negative number; numeric ln and base-log paths apply the same SQLSTATE while handling NaN and infinities separately.

Meaning

2201E is a logarithm domain error, not a generic numeric overflow. In float.c, ln() and log() reject an argument equal to zero and then one less than zero. Numeric ln rejects negative infinity but returns numeric NaN or positive infinity unchanged; numeric base-log rejects a negative or zero base/argument and has defined NaN/infinity results for some positive special-value combinations.

Diagnosis

Read the function signature and the actual numeric type before changing the value. Match the primary message: zero and negative inputs are different guards. For float inputs, NaN does not satisfy either comparison and therefore is not this particular guard; later float overflow or underflow reports are separate conditions. Preserve the input and business rule while checking whether the logarithm domain is really intended.

Response

Supply a value in the domain required by the named logarithm function, or change the business rule explicitly. If an ERROR occurred inside an explicit transaction, roll back or roll back to the existing savepoint before retrying; an autocommit client can retry the corrected statement. Casting blindly can move the value without making the operation defined.

Versions

The locked catalogue records this condition from 8.0.0; the fixed source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

Sources

Fixed paths include src/backend/utils/adt/float.c#L1687-1747 and src/backend/utils/adt/numeric.c#L3935-4020 plus #L11156-11168, which bind the zero/negative guards and special-value branches. The structured evidence record retains the exact message roles and scope boundary; no natural runtime was run.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

2201E is invalid_argument_for_logarithm in SQLSTATE Class 22

Method: Read the fixed errcodes row and macro.

src.errcodes.18.6

Fixed PostgreSQL 18.6 float and numeric logarithm paths bind zero/negative guards and distinct NaN/infinity handling for both ln and base-log operations.

Method: Read complete source contexts for the representative guards.

Limits: Source confirmation is not a natural runtime observation.

src.float.log src.numeric.log src.numeric.ln.finite

The locked catalogue records 2201E from 8.0.0 without proving an exact implementation introduction date.

Method: Use catalogue presence and history boundaries.

src.errcodes.18.6

Message templates

ERROR · message.zero

Primary

cannot take logarithm of zero
ERROR · message.negative

Primary

cannot take logarithm of a negative number

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:4df9e83cc1331d6566c9bcf3043… · English manual source