0

I created a table "TEST" and i tried to input some data however i got an error. The error is ERROR: new row for relation "test" violates check constraint "test_status_check" DETAIL: Failing row contains (5 , 2015-07-21, 15:00:00, I7 , 9 , NULL, NULL). I think it is because of the null of the status. Therefore, i tried put a null in the test table but still not working

Create table test(
    clientID CHAR (20),
    startDate date,
    startTime time,
    instructorNO CHAR(20),
    centreID  CHAR(20), 
    status CHAR(4) CHECK (status IN ('Fail','Pass')) NULL,
    reason VARCHAR(400),

    omitted...
    )

ERROR: new row for relation "test" violates check constraint "test_status_check" DETAIL: Failing row contains (5 , 2015-07-21, 15:00:00, I7 , 9 , NULL, NULL).

3
  • 1
    is this mysql or postegresql?? Commented Apr 7, 2015 at 18:00
  • Postgres 9.3 accept your syntax, however, really what is it exactly that you want. Postgres, MySQL, and which version?? Commented Apr 7, 2015 at 18:03
  • I removed the MySQL tag since the title clearly says PostgreSQL (and last time I checked, CHECK constraints don't work in MySQL anyway). Commented Apr 7, 2015 at 18:10

1 Answer 1

2

EDIT: I've completely changed my mind. Your existing code is valid (and the NULL part is unnecessary).

According to the 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.

So, something else is messed up. See here for an example of your original code working.

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

4 Comments

@Bredan Long when i input some data in the table error occur Query failed: ERROR: new row for relation "test" violates check constraint "test_status_check" DETAIL: Failing row contains (2 , 2015-04-29, 10:00:00, I2 , 1 , NULL, NULL).
@nicholaslui Are you sure you removed the old constraint?
Hm, weirdly.. your original code works for me on PostgreSQL 9.3.6 :\
hahaha i solve it out lol i put a '' in NULL thats why! thankyou!

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.