BUG #4888: Removed brackets from Check Constraints expressions

Started by stalkeralmost 17 years ago2 messagesbugs
Jump to latest
#1stalker
chimera@bk.ru

The following bug has been logged online:

Bug reference: 4888
Logged by: stalker
Email address: chimera@bk.ru
PostgreSQL version: 8.3.7
Operating system: Debian 4.0 (etch)
Description: Removed brackets from Check Constraints expressions
Details:

I try to create Check Constraints for DB with Nested Set data model. When I
write complex validation rule with OR-operator - result Description is
incorrect.

CREATE TABLE Catalog
(
id integer,
id_lft integer, -- nested set
id_rgt integer,
);

ALTER TABLE Catalog
ADD CONSTRAINT ctg_check_ns CHECK (id_lft > id_rgt OR (id_lft = 0 AND
id_lft = 0));

Result:
'ctg_check_ns' Definition == "id_lft > id_rgt OR id_lft = 0 AND id_lft =
0".

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: stalker (#1)
Re: BUG #4888: Removed brackets from Check Constraints expressions

"stalker" <chimera@bk.ru> writes:

I try to create Check Constraints for DB with Nested Set data model. When I
write complex validation rule with OR-operator - result Description is
incorrect.

ALTER TABLE Catalog
ADD CONSTRAINT ctg_check_ns CHECK (id_lft > id_rgt OR (id_lft = 0 AND
id_lft = 0));

Result:
'ctg_check_ns' Definition == "id_lft > id_rgt OR id_lft = 0 AND id_lft =
0".

Looks perfectly correct to me. AND binds more tightly than OR.

regards, tom lane