Re: Fix numeric log() with an infinite value and 0<base<=1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix numeric log() with an infinite value and 0<base<=1
Date: 2026-10-14 15:07:39
Message-ID: 1174673.1791990459@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com> writes:
> On Wed, 14 Oct 2026 at 13:17, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>> The SQL function log() returns incorrect results in these cases:
>> evantest=# SELECT log(0.5::numeric, 'Infinity'::numeric);
>> log
>> ----------
>> Infinity
>> (1 row)
>> evantest=# SELECT log(1::numeric, 'Infinity'::numeric);
>> log
>> ----------
>> Infinity
>> (1 row)

> I don't think that we should match Python on this,

Indeed; Python is not our reference implementation. But the SQL spec
does say that log(1, anything) is an error.

> So, I'd suggest something like

> + if (cmp_var(, const_one) == 0)
> + ereport(ERROR,
> + errcode(ERRCODE_INVALID_ARGUMENT_FOR_LOG),
> + errmsg("cannot take logarithm using base 1"));

Agreed, but if we want that, we must do it for a finite second input
too. Right now you do get

regression=# select log(1, 33);
ERROR: division by zero

Chao proposes matching that, which isn't insane, but I like a
specialized error message better.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Aidar Imamov 2026-10-14 15:08:36 Re: meson: pass OpenSSL/ICU include dirs to extensions
Previous Message Nisha Moond 2026-10-14 14:46:22 Re: Proposal: Conflict log history table for Logical Replication