On Thu, Dec 18, 2014 at 11:51:12PM -0500, Tom Lane wrote: > If you're doing any sort of higher math or statistics, I stand by my > statement that you'd better think rather than just blindly assume that > numeric is going to be better for you. A moment's fooling about finds > this example, which is pretty relevant to the formula we started this > thread with: > > regression=# select (1234::numeric/1235) * 1235; > ?column? > --------------------------- > 1234.00000000000000000100 > (1 row) > > regression=# select (1234::float8/1235) * 1235; > ?column? > ---------- > 1234 > (1 row) > > What it boils down to is that numeric is great for storing given decimal > inputs exactly, and it can do exact addition/subtraction/multiplication > on those too, but as soon as you get into territory where the result is > fundamentally inexact it is *not* promised to be better than float8. > In fact, it's designed to be more or less the same as float8; see the > comments in select_div_scale.
Based on the analysis above, I have written the attached patch to the NUMERIC docs to mention this. -- Bruce Momjian <br...@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. +
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml new file mode 100644 index edf636b..4a65971 *** a/doc/src/sgml/datatype.sgml --- b/doc/src/sgml/datatype.sgml *************** *** 498,508 **** <para> The type <type>numeric</type> can store numbers with a ! very large number of digits and perform calculations exactly. It is ! especially recommended for storing monetary amounts and other ! quantities where exactness is required. However, arithmetic on ! <type>numeric</type> values is very slow compared to the integer ! types, or to the floating-point types described in the next section. </para> <para> --- 498,510 ---- <para> The type <type>numeric</type> can store numbers with a ! very large number of digits. It is especially recommended for ! storing monetary amounts and other quantities where exactness is ! required. Calculations with <type>numeric</type> values yield exact ! results where possible, e.g. addition, subtraction, multiplication. ! However, calculations on <type>numeric</type> values is very slow ! compared to the integer types, or to the floating-point types ! described in the next section. </para> <para>
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers