pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
BUG #9820: Parentheses removed in chech constraint 2+ messages / 2 participants [nested] [flat]
* BUG #9820: Parentheses removed in chech constraint @ 2014-04-01 15:01 ilussier@accovia.com 2014-04-01 18:41 ` Re: BUG #9820: Parentheses removed in chech constraint Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: ilussier@accovia.com @ 2014-04-01 15:01 UTC (permalink / raw) To: pgsql-bugs The following bug has been logged on the website: Bug reference: 9820 Logged by: Isabelle Lussier Email address: ilussier@accovia.com PostgreSQL version: 9.3.2 Operating system: Windows (PgAdmin) Description: Hi, I'am want to add a check constraint that checks if the first condition is true OR the second condition is true. If one of the two conditions is true, then the check is true. Example: alter table table_name add constraint c1 CHECK ( (type = 0 AND field1 IS NOT NULL AND field2 IS NOT NULL AND field3 IS NOT NULL) OR (type_id = 1 AND field1 IS NULL AND field2 IS NULL AND field3 IS NULL) ) At the execution of the query, the parentheses that defines condition 1 and condition 2 are removed. By removing the parentheses, the expression does not means the same thing. Why postgresql removes the parentheses or how can I do the constraint differently? -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #9820: Parentheses removed in chech constraint 2014-04-01 15:01 BUG #9820: Parentheses removed in chech constraint ilussier@accovia.com @ 2014-04-01 18:41 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2014-04-01 18:41 UTC (permalink / raw) To: ilussier@accovia.com; +Cc: pgsql-bugs ilussier@accovia.com writes: > alter table table_name add constraint c1 CHECK ( (type = 0 AND field1 IS NOT > NULL AND field2 IS NOT NULL AND field3 IS NOT NULL) OR (type_id = 1 AND > field1 IS NULL AND field2 IS NULL AND field3 IS NULL) ) > At the execution of the query, the parentheses that defines condition 1 and > condition 2 are removed. By removing the parentheses, the expression does > not means the same thing. Sure it does. AND binds more tightly than OR. You did not state what your actual problem is, but whether or not the constraint-printer adds logically redundant parentheses isn't it... regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2014-04-01 18:41 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2014-04-01 15:01 BUG #9820: Parentheses removed in chech constraint ilussier@accovia.com 2014-04-01 18:41 ` Tom Lane <tgl@sss.pgh.pa.us>
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