Unix Technical Forum

pgsql: Fix NUMERIC modulus to properly truncate division in computation.

This is a discussion on pgsql: Fix NUMERIC modulus to properly truncate division in computation. within the pgsql Committers forums, part of the PostgreSQL category; --> Log Message: ----------- Fix NUMERIC modulus to properly truncate division in computation. Division rounding was causing incorrect results. Test ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Committers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:04 PM
Bruce Momjian
 
Posts: n/a
Default pgsql: Fix NUMERIC modulus to properly truncate division in computation.

Log Message:
-----------
Fix NUMERIC modulus to properly truncate division in computation.
Division rounding was causing incorrect results. Test case:

test=> SELECT 12345678901234567890 % 123;
?column?
----------
78
(1 row)

Was returning -45.

Modified Files:
--------------
pgsql/src/backend/utils/adt:
numeric.c (r1.83 -> r1.84)
(http://developer.postgresql.org/cvsw...1=1.83&r2=1.84)

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:04 PM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: pgsql: Fix NUMERIC modulus to properly truncate

Is this a backport?

Bruce Momjian wrote:
> Log Message:
> -----------
> Fix NUMERIC modulus to properly truncate division in computation.
> Division rounding was causing incorrect results. Test case:
>
> test=> SELECT 12345678901234567890 % 123;
> ?column?
> ----------
> 78
> (1 row)
>
> Was returning -45.
>
> Modified Files:
> --------------
> pgsql/src/backend/utils/adt:
> numeric.c (r1.83 -> r1.84)
> (http://developer.postgresql.org/cvsw...1=1.83&r2=1.84)
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 12:04 PM
Bruce Momjian
 
Posts: n/a
Default Re: pgsql: Fix NUMERIC modulus to properly truncate

Christopher Kings-Lynne wrote:
> Is this a backport?


No, I don't think so. It doesn't seem to be something that enough
people use to risk the change in behavior --- it might break something
that was working. But, if folks want it backported we can do it. It is
only a change to properly do modulus for numeric.

---------------------------------------------------------------------------


>
> Bruce Momjian wrote:
> > Log Message:
> > -----------
> > Fix NUMERIC modulus to properly truncate division in computation.
> > Division rounding was causing incorrect results. Test case:
> >
> > test=> SELECT 12345678901234567890 % 123;
> > ?column?
> > ----------
> > 78
> > (1 row)
> >
> > Was returning -45.
> >
> > Modified Files:
> > --------------
> > pgsql/src/backend/utils/adt:
> > numeric.c (r1.83 -> r1.84)
> > (http://developer.postgresql.org/cvsw...1=1.83&r2=1.84)
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly

>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>


--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 12:05 PM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: pgsql: Fix NUMERIC modulus to properly truncate

> No, I don't think so. It doesn't seem to be something that enough
> people use to risk the change in behavior --- it might break something
> that was working. But, if folks want it backported we can do it. It is
> only a change to properly do modulus for numeric.


Well, from my point of view it's an absolute mathematical error - i'd
backport it. I can't see anyone relying on it

Chris

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 12:05 PM
Tom Lane
 
Posts: n/a
Default Re: pgsql: Fix NUMERIC modulus to properly truncate

Christopher Kings-Lynne <chriskl@familyhealth.com.au> writes:
>> No, I don't think so. It doesn't seem to be something that enough
>> people use to risk the change in behavior --- it might break something
>> that was working. But, if folks want it backported we can do it. It is
>> only a change to properly do modulus for numeric.


> Well, from my point of view it's an absolute mathematical error - i'd
> backport it. I can't see anyone relying on it


Doesn't this patch break the basic theorem that

a = trunc(a / b) * b + (a mod b)

? If division rounds and mod doesn't, you've got pretty serious issues.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com