| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Matthias van de Meent <boekewurm+postgres(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-15 02:16:08 |
| Message-ID: | F09602BB-F461-4096-8D5B-7CDE595714DC@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Oct 14, 2026, at 23:07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> 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.
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/
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-numeric-log-with-an-infinite-argument-and-a-b.patch | application/octet-stream | 4.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bharath Rupireddy | 2026-10-15 02:19:40 | Re: Parallel vacuum: avoid dangling shared memory pointers |
| Previous Message | Bharath Rupireddy | 2026-10-15 02:14:15 | Re: Parallel autovacuum: DROP DATABASE WITH (FORCE) fails on the parallel workers |