pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: kaleb.akalework@asg.com
Subject: BUG #15812: Select statement of a very big number, with a division operator seems to round up.
Date: Fri, 17 May 2019 15:46:17 +0000
Message-ID: <15812-adda7f0f3359803c@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15812
Logged by:          Kaleb Akalework
Email address:      kaleb.akalework@asg.com
PostgreSQL version: 11.3
Operating system:   Windows/Linux
Description:        

I have a need to divide a big number numeric(20) by 10000000000 to feed it
into a floor function. The division operation rounds up the number which
causes problems. I need the division to just divide the number without
rounding up or down. For my purposes 3691635539999999999/10000000000 should
return 369163553.9999999999 not 369163554. This happens if the data is
retrieved from a column. Below are queries to reproduce the problem

create table test_table
(
    REQUEST_UUID varchar(50) not null,
    BIG_NUM numeric(20,0) not null
);

INSERT INTO test_table (REQUEST_UUID, BIG_NUM) values ('TEST',
3691635539999999999);
INSERT INTO test_table (REQUEST_UUID, BIG_NUM) values('TEST',
3691635530099999999);
INSERT INTO test_table (REQUEST_UUID, BIG_NUM) values('TEST',
3691635530999999999);

SELECT BIG_NUM, FLOOR(BIG_NUM/10000000000),  BIG_NUM/10000000000 from
test_table;

The following is the result of the above select. you can see that column 2
for first row was rounded up.

"3691635539999999999"	"369163554"	"369163554.00000000"
"3691635530099999999"	"369163553"	"369163553.01000000"
"3691635530999999999"	"369163553"	"369163553.10000000"



view thread (9+ messages)  latest in thread

Message-ID: <15812-adda7f0f3359803c@postgresql.org>
Permalink:  ../15812-adda7f0f3359803c@postgresql.org/
Also on:    postgresql.org/message-id/15812-adda7f0f3359803c@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, kaleb.akalework@asg.com
  Subject: Re: BUG #15812: Select statement of a very big number, with a division operator seems to round up.
  In-Reply-To: <15812-adda7f0f3359803c@postgresql.org>
  References: <15812-adda7f0f3359803c@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox