Re: BUG #15812: Select statement of a very big number, with a division operator seems to round up.

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Kaleb Akalework <kaleb(dot)akalework(at)asg(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15812: Select statement of a very big number, with a division operator seems to round up.
Date: 2019-05-17 18:02:52
Message-ID: CAEZATCWLQ3p6sHkQ7mF9hMtkX4xaJDxmgO1mHh760BZ_B9W5Fg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 17 May 2019 at 17:36, Kaleb Akalework <kaleb(dot)akalework(at)asg(dot)com> wrote:
>
> I tried Andres suggestion in his last email and that seems to work as a work around. Please see below.
>
> SELECT BIG_NUM, FLOOR(BIG_NUM /10000000000.0000000000), BIG_NUM/10000000000.0000000000 from test_table
>
> "3691635539999999999" "369163553" "369163553.9999999999"
> "3691635530099999999" "369163553" "369163553.0099999999"
> "3691635530999999999" "369163553" "369163553.0999999999"
>
> But should this be a bug? Can their a better support of this, instead of having the query writer to know how many decimal numbers to put to get the correct type?
>
> It seems a little awkward and error prone to have to type .0000.... etc?
>

I would suggest using the numeric div() function, which divides a pair
of numeric values, and returns the truncated integer result. I.e.,
div(big_num, 10000000000). For example:

SELECT div(3691635539999999999::numeric(20, 0), 10000000000);
returns 369163553.

See https://www.postgresql.org/docs/current/functions-math.html

Regards,
Dean

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2019-05-17 20:24:43 Re: BUG #15804: Assertion failure when using logging_collector with EXEC_BACKEND
Previous Message Kaleb Akalework 2019-05-17 16:36:19 RE: BUG #15812: Select statement of a very big number, with a division operator seems to round up.