Re: BUG #15812: Select statement of a very big number, with adivision operator seems to round up.
От | Dean Rasheed |
---|---|
Тема | Re: BUG #15812: Select statement of a very big number, with adivision operator seems to round up. |
Дата | |
Msg-id | CAEZATCWLQ3p6sHkQ7mF9hMtkX4xaJDxmgO1mHh760BZ_B9W5Fg@mail.gmail.com обсуждение исходный текст |
Ответ на | RE: BUG #15812: Select statement of a very big number, with adivision operator seems to round up. (Kaleb Akalework <kaleb.akalework@asg.com>) |
Список | pgsql-bugs |
On Fri, 17 May 2019 at 17:36, Kaleb Akalework <kaleb.akalework@asg.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 decimalnumbers 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
В списке pgsql-bugs по дате отправления: