pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Niklas Johansson <spot@tele2.se>
To: Risto Tamme <risto@ektaco.ee>
Cc: pgsql-sql@postgresql.org
Subject: Re: Table constraints and INSERT
Date: Wed, 17 May 2006 12:49:38 +0200
Message-ID: <4FECA253-3236-4619-B317-765B4CBE9DDD@tele2.se> (raw)
In-Reply-To: <E763584E741976409B9F835B475B00FC1A5353@pe2850.EKTACO.local>
References: <E763584E741976409B9F835B475B00FC1A5353@pe2850.EKTACO.local>


On 17 maj 2006, at 08.42, Risto Tamme wrote:
> INSERT INTO "PART" ("P_PARTKEY","P_RETAILPRICE") VALUES(999,90109.89);
>
> but it fails: ERROR:  new row for relation "PART" violates check
> constraint "PART_check"

The P_PARTKEY column is an integer, which means the expression  
P_PARTKEY/10 will yield 99, *not* 99.9.

Try executing

SELECT 90000 + 999/10 + 999/10;

from psql or some GUI-utility; the result is 90108.

> When you check using your head or pocket calculator then this INSERT
> seems to be correct. Is it some floating point mystery?
> Is there some trick?

You must cast the integer column to a float or numeric, try:

SELECT 90000 + 999::numeric/10 + 999::numeric/100;

In your case:

CHECK ("P_RETAILPRICE" = (90000 + "P_PARTKEY"::numeric / 10 +  
"P_PARTKEY"::numeric / 100)



Sincerely,

Niklas Johansson
Phone: +46-322-108 18
Mobile: +46-708-55 86 90





view thread (3+ messages)  latest in thread

Message-ID: <4FECA253-3236-4619-B317-765B4CBE9DDD@tele2.se>
Permalink:  ../4FECA253-3236-4619-B317-765B4CBE9DDD@tele2.se/
Also on:    postgresql.org/message-id/4FECA253-3236-4619-B317-765B4CBE9DDD@tele2.se

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: spot@tele2.se, risto@ektaco.ee
  Subject: Re: Table constraints and INSERT
  In-Reply-To: <4FECA253-3236-4619-B317-765B4CBE9DDD@tele2.se>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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