Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UfA8s-0004qM-Mt for pgsql-bugs@arkaria.postgresql.org; Wed, 22 May 2013 14:35:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UfA8s-0005Th-2U for pgsql-bugs@arkaria.postgresql.org; Wed, 22 May 2013 14:35:50 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UfA6w-0005KL-Sp for pgsql-bugs@postgresql.org; Wed, 22 May 2013 14:33:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UfA6q-0006ZZ-M7 for pgsql-bugs@postgresql.org; Wed, 22 May 2013 14:33:50 +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 r4MEXgHL007002; Wed, 22 May 2013 10:33:43 -0400 (EDT) From: Tom Lane To: dan.libby@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8175: Check constraint fails for valid data. ( rounding related? ) In-reply-to: References: Comments: In-reply-to dan.libby@gmail.com message dated "Wed, 22 May 2013 00:56:57 -0000" Date: Wed, 22 May 2013 10:33:42 -0400 Message-ID: <7001.1369233222@sss.pgh.pa.us> X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org dan.libby@gmail.com writes: > create table test1 ( > val1 numeric(23,8), > val2 numeric(23,8), > product numeric(23,8) check( product = val1 * val2 ) > ); > select (2.23567567*3.70000000)::numeric(23,8); > insert into test1 values ( 3.70000000, 2.23567567, 8.27199998 ); > insert into test1 values ( 3.70000000, 2.23567567, 2.23567567*3.70000000 ); > insert into test1 values ( 3.70000000, 2.23567567, > (2.23567567*3.70000000)::numeric(23,8) ); It's not surprising that these all fail. You'd need to make the check be more like this: check( product = (val1 * val2)::numeric(23,8) ) Otherwise, the check will always fail when the product has more than 8 fractional digits. It's not Postgres' place to decide that that wasn't what you wanted to happen. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs