I have a table with columns: c1, c2, c3, c4 And I am trying to add a CONSTRAINT check The conditions are:
- if c4 is not null then c1,c2,c3 all must not null.
- else if c4 is null then c1,c2,c3 are optional but at least one field must be non-null.
Here is my sql command:
ADD CONSTRAINT quatereulchk CHECK(
(c1 IS NOT NULL AND c2 IS NOT NULL AND c3 IS NOT NULL AND c4 IS NOT NULL)
OR
(c4 IS NULL AND c1 IS NOT NULL OR c2 IS NOT NULL OR c3 IS NOT NULL)
);
I tested with pg_admin however the constrain is not working. Thanks!
ANDandOR. If we talked about maths your DDL expects that2 * 2 + 2equals to8