> On Oct 14, 2026, at 23:07, Tom Lane <[email protected]> wrote: > > Matthias van de Meent <[email protected]> writes: >> On Wed, 14 Oct 2026 at 13:17, Chao Li <[email protected]> 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.
I didn’t intend to follow Python’s error message. I was just verifying that
this case should raise 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.
>
That’s why I chose that error message, because the existing test has this:
```
select log(1.0, 12.34);
ERROR: division by zero
```
After thinking it over, I think we can add a check for base 1 in log_var(), and
numeric_log() can just defer base 1 handling to log_var(). Please see v2, which
implements this approach.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
v2-0001-Fix-numeric-log-with-an-infinite-argument-and-a-b.patch
Description: Binary data
