Question about the TODO, numerics, and division - Mailing list pgsql-hackers

From Chris Travers
Subject Question about the TODO, numerics, and division
Date
Msg-id 46005C1F.5040607@metatrontech.com
Whole thread Raw
Responses Re: Question about the TODO, numerics, and division
List pgsql-hackers
Hi all;

I have been looking at the TODO and have found something that I find
sort of odd and we should probably reconsider:

One of the items under data types is:

    * Add NUMERIC division operator that doesn't round?

      Currently NUMERIC _rounds_ the result to the specified precision.
      This means division can return a result that multiplied by the
      divisor is greater than the dividend, e.g. this returns a value > 10:

SELECT (10::numeric(2,0) / 6::numeric(2,0))::numeric(2,0) * 6;

This does not seem to me to be an division op issue but rather a simple
casting mistake.  Note that the result of 10/6 is cast as numeric(2,0)
and then multiplied by 6.

The following example shows that the problem is with the query and
casting, not with the division op:
SELECT ((10::numeric(2,0) / 6::numeric(2,0)) * 6)::numeric(2,0);
 numeric
---------
      10
(1 row)


Am I missing something?

Best Wishes,
Chris Travers



Attachment

pgsql-hackers by date:

Previous
From: "Florian G. Pflug"
Date:
Subject: Re: modifying the tbale function
Next
From: Gavin Sherry
Date:
Subject: Re: Bitmapscan changes - Requesting further feedback