2

I have the sample table definition below. Is it possible to create a check constraint wherein the column affected can be nullable?

CREATE TABLE task (
    # other definition
    registered_date timestamp without time zone NOT NULL,
    completed_date timestamp without time zone
    # constraints
);

I was planning to imply a constraint check on completed_date so that the input value won't be lesser than registered_date. Is this possible?

0

1 Answer 1

4

Yes. Check constraints accept NULL values automatically. Per documentation:

It should be noted that a check constraint is satisfied if the check expression evaluates to true or the null value. Since most expressions will evaluate to the null value if any operand is null, they will not prevent null values in the constrained columns. To ensure that a column does not contain null values, the not-null constraint described in the next section can be used.

Bold emphasis mine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.