Re: BUG #8175: Check constraint fails for valid data. ( rounding related? )

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: dan(dot)libby(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #8175: Check constraint fails for valid data. ( rounding related? )
Date: 2013-05-22 14:33:42
Message-ID: 7001.1369233222@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

dan(dot)libby(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message tushar 2013-05-22 14:35:33 Re: pass to install
Previous Message juancho gonzila jorrel 2013-05-22 14:20:40 pass to install