Re: unexpected check constraint violation

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Jacek Becla <becla(at)slac(dot)stanford(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: unexpected check constraint violation
Date: 2009-03-23 21:01:20
Message-ID: dcc563d10903231401l32d5224buc150f26bb8595c86@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 23, 2009 at 1:54 PM, Jacek Becla <becla(at)slac(dot)stanford(dot)edu> wrote:
> Hi,
>
> Can someone explain why postgres complains in this case:
>
> create table t(d real, check(d>=0.00603));
> insert into t values (0.00603);
>
> ERROR:  new row for relation "t" violates check constraint "t_d_check"

Without any casting, 0.00603 likely evaluates to a numeric.

select 0.00603::numeric > 0.00603::real;
?column?
----------
t

So, this works:

create table t(d real, check(d>=0.00603::real));
insert into t values (0.00603);
INSERT 0 1

In response to

Browse pgsql-general by date

  From Date Subject
Next Message RebeccaJ 2009-03-23 21:11:28 Re: text column constraint, newbie question
Previous Message Whit Armstrong 2009-03-23 21:00:43 libpq -- reading a timestamp with time zone using binary format