Table constraints and INSERT

Поиск
Список
Период
Сортировка
Искать
От
Risto Tamme
Тема
Table constraints and INSERT
Дата
в 03:42:50
Msg-id
E763584E741976409B9F835B475B00FC1A5353@pe2850.EKTACO.local
Список
Дерево обсуждения
Table constraints and INSERT "Risto Tamme" <risto@ektaco.ee>
Re: Table constraints and INSERT Niklas Johansson <spot@tele2.se>
Re: Table constraints and INSERT Tom Lane <tgl@sss.pgh.pa.us>
Hello

I use PostgreSQL in my program and I found a strange behavior, at least
for me.

I have a simple table with constraint

CREATE TABLE "PART"
( "P_PARTKEY" int4 NOT NULL, "P_RETAILPRICE" numeric, CONSTRAINT "PART_PRIMARY" PRIMARY KEY ("P_PARTKEY"), CONSTRAINT "PART_check" CHECK ("P_RETAILPRICE" = (90000 + "P_PARTKEY"
/ 10 + "P_PARTKEY" / 100)
);

And I try to insert a row:
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"

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?
I'm using version 8.0.1 for Windows.

With thanks, Risto

В списке pgsql-sql по дате отправления
От: Emi Lu
Дата:
От: Kis János Tamás
Дата:
Сообщение: Database OID
FAQ