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.
> 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