pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8175: Check constraint fails for valid data. ( rounding related? )
2+ messages / 2 participants
[nested] [flat]

* BUG #8175: Check constraint fails for valid data. ( rounding related? )
@ 2013-05-22 00:56  dan.libby@gmail.com
  0 siblings, 1 reply; 2+ messages in thread

From: dan.libby@gmail.com @ 2013-05-22 00:56 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8175
Logged by:          Dan Libby
Email address:      dan.libby@gmail.com
PostgreSQL version: 9.1.6
Operating system:   Linux  ( Ubuntu 12.04 )
Description:        

-- Try this script --

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) );


-- Actual Results --

select (2.23567567*3.70000000)::numeric(23,8);
numeric | 8.27199998

btcx=# insert into test1 values ( 3.70000000, 2.23567567, 8.27199998 );
ERROR:  new row for relation "test1" violates check constraint
"test1_check"
btcx=# insert into test1 values ( 3.70000000, 2.23567567,
2.23567567*3.70000000 );
ERROR:  new row for relation "test1" violates check constraint
"test1_check"
btcx=# insert into test1 values ( 3.70000000, 2.23567567,
(2.23567567*3.70000000)::numeric(23,8) );
ERROR:  new row for relation "test1" violates check constraint
"test1_check"


-- Expected Results --

All values should be inserted successfully.





-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #8175: Check constraint fails for valid data. ( rounding related? )
@ 2013-05-22 14:33  Tom Lane <tgl@sss.pgh.pa.us>
  parent: dan.libby@gmail.com
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2013-05-22 14:33 UTC (permalink / raw)
  To: dan.libby@gmail.com; +Cc: 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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-05-22 14:33 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-05-22 00:56 BUG #8175: Check constraint fails for valid data. ( rounding related? ) dan.libby@gmail.com
2013-05-22 14:33 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox