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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #8175: Check constraint fails for valid data. ( rounding related? )
Дата
Msg-id 7001.1369233222@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #8175: Check constraint fails for valid data. ( rounding related? )  (dan.libby@gmail.com)
Список pgsql-bugs
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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: juancho gonzila jorrel
Дата:
Сообщение: pass to install
Следующее
От: tushar
Дата:
Сообщение: Re: pass to install