Re:Re: BUG #19101: Ceil on BIGINT could lost precision in decil function

From: dqetool <dqetool(at)126(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re:Re: BUG #19101: Ceil on BIGINT could lost precision in decil function
Date: 2025-11-03 02:48:34
Message-ID: 43e5b082.29f0.19a479dcb70.Coremail.dqetool@126.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Thanks for the quick response. I try to add an explicit type conversion to avoid this problem.
At 2025-11-03 00:35:26, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
>> I try to store a large number in `BIGINT` and run `ceil(c1)` command.
>> However, the result lost some precision due to calling `decil` function.
>> ```sql
>> CREATE TABLE t1 (c1 BIGINT);
>> INSERT INTO t1 VALUES (4854233034440979799);
>> -- dceil
>> SELECT ceil(c1) FROM t1; -- {4.854233034440979e+18}
>> ```
>
>This is not a bug. There are two versions of ceil() and you're
>invoking the wrong one. You'd need to explicitly cast the
>argument to numeric if you want ceil(numeric) to be used.
>
>In this context it's a bit unfortunate that the parser's type
>preference rules [1] prefer float8 to numeric. But we're pretty
>much stuck with that behavior because (a) the SQL standard
>says so [2], and (b) even if it didn't, we have a couple of
>decades of history to be backwards compatible with.
>
> regards, tom lane
>
>[1] https://www.postgresql.org/docs/current/typeconv.html
>
>[2] Well, what it really says is that expressions that mix
>exact and inexact numeric types produce inexact results.
>We interpret that as meaning that float8 is the preferred
>type in the numeric category, so it wins ambiguous cases.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-11-03 05:51:09 BUG #19102: Assertion failure in generate_orderedappend_paths with aggregate pushdown
Previous Message Tom Lane 2025-11-02 18:36:12 Re: BUG #19100: Different column type between partitioned table and detached pending partition table make errors