of 2 fields filled in in my database
I have a table with 3 fields
id INT Primary key,
email VARCHAR,
phone_number VARCHAR
email and phone_number are nullable,
I've added a CHECK Constraint to my table
ALTER TABLE my_table ADD CHECK(email != NULL OR phone_number != NULL);
But it just seems like doesn't work, I can INSERT into the table without providing email and phone_number,
https://dbfiddle.uk/?rdbms=postgres_11&fiddle=bbbabdba9884f8cf2abca32deba307ba
Here is an example
Also tried with x is NULL OR y is NULL, x is NULL AND y is NULL and x != NULL AND y != NULL, None of them worked
What might be the problem? How can I fix it?
Nothing equals to NULL :) Use email IS NOT NULL syntax.
Обсуждают сегодня