8

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;
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
Hemadri Dasari
  • 32,666
  • 37
  • 119
  • 162

1 Answers1

16

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360