10

I have existing table called test with two columns id and utilized

Here utilized contains three values in my table null, false and true. Here null is default for utilized

I want to update the rows with utilized false where utilized is null so I tried below query in Postgres but it didn’t work for me.

  update test set utilized=false where utilized=null;

1 Answer 1

22

You must use IS NULL to check for the presence of a NULL value:

UPDATE test
SET utilized = false
WHERE utilized IS NULL;

In SQL, unlike other places such as Java or C#, NULL is a special value meaning something like "not known." Therefore, comparing a column to NULL using the = operator is also unknown, because it might or might not be true. Instead, use IS NULL or IS NOT NULL to directly compare a column to NULL.

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.