Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 625411E3525C for ; Thu, 12 Jul 2012 14:30:33 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SpNDk-0008KC-Jc for pgsql-sql@postgresql.org; Thu, 12 Jul 2012 17:30:32 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q6CHUJLt029731; Thu, 12 Jul 2012 13:30:19 -0400 (EDT) From: Tom Lane To: Will Pugh cc: pgsql-sql@postgresql.org Subject: Re: How does Numeric division determine precision? In-reply-to: References: Comments: In-reply-to Will Pugh message dated "Thu, 12 Jul 2012 09:02:03 -0700" Date: Thu, 12 Jul 2012 13:30:19 -0400 Message-ID: <29730.1342114219@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/14 X-Sequence-Number: 36751 Will Pugh writes: > It seems that is 9.1, numerics that don't have a specified precision > and scale are arbitrary scale/precision. > For many operations this is straightforward. However, when doing a > division operation that does not terminate, I'm curious about how the > number of digits is determined. According to select_div_scale() in src/backend/utils/adt/numeric.c, /* * The result scale of a division isn't specified in any SQL standard. For * PostgreSQL we select a result scale that will give at least * NUMERIC_MIN_SIG_DIGITS significant digits, so that numeric gives a * result no less accurate than float8; but use a scale not less than * either input's display scale. */ I wouldn't necessarily claim that that couldn't be improved on, but that's what it does now. regards, tom lane