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: ries van Twisk <pg(at)rvt(dot)dds(dot)nl>, pgsql-general(at)postgresql(dot)org
Subject: Re: unexpected check constraint violation
Date: 2009-03-23 22:28:20
Message-ID: dcc563d10903231528k19cf55f6ia58d249a77180faf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 23, 2009 at 2:52 PM, Jacek Becla <becla(at)slac(dot)stanford(dot)edu> wrote:
> Thanks Ries. Do you know if that is a postgres feature or a bug?

It's not a bug, it's lack of precision in the definition on your part
being interpreted by pgsql. When you create the table, you get this:

create table t(d real, check(d>=0.00603));
\d t
Table "public.t"
Column | Type | Modifiers
--------+------+-----------
d | real |
Check constraints:
"t_d_check" CHECK (d >= 0.00603::double precision)

Note that having not been told the type for the check constraint,
pgsql defaults to double precision. So, in effect, your table
creation was this:

create table t(d real, check(d>=0.00603::double precision));

You can either cast the check constraint, or change the field type to
match double precision.

create table t(d double precision, check(d>=0.00603::double precision));
create table t(d real, check(d>=0.00603::real));

Either of those will work properly.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-03-23 22:31:44 Re: text column constraint, newbie question
Previous Message Harvey, Allan AC 2009-03-23 22:06:30 Re: LISTEN/NOTIFY problem