Trying to filter features based on whether one field has value or not.

enter image description here

After looking up a number of web pages (including the two from this forum), I believe the expression should be:

"name" IS NOT NULL

However, the above expression returns all the rows.

enter image description here

When I try "name" IS NULL, no row was returned.

enter image description here

Applying these expressions to other fields yields the same results. Can anyone shed some light on what I might have missed, please?

Relevant threads:
Selecting features with NULL attributes in QGIS?
How to select features where attribute is not NULL?

QGIS version 3.12.3-București

  • 2
    are your attributes NULL or just empty '' ? – Ian Turton May 23 '20 at 15:34
  • 1
    As @IanTurton said, first inclination is to suspect name is '' not NULL. You could check by temporarily adding a virtual field in the field calculator with the expression length("name"), which will return 0 if they're '' and NULL if they're really NULL. – Houska May 23 '20 at 16:34
  • Oh my didn't see that coming. Yes, the length of empty cells are all 0! This is OSM export. Does it mean attributes are by default ''? Also, I cannot seem to find the "check mark beside the answer to toggle it from greyed out to filled in". Is it because these are categorised as "comments" instead of "answers"? Then how should I close this question? – Howard May 23 '20 at 23:11
  • Do you use shapefiles? Shapefiles or actually the dBase III format used for storing attributes does not support nulls. See github.com/OSGeo/gdal/issues/2486 that is somewhat related. – user30184 May 25 '20 at 11:21
  • That would make sense. If NULL is not universally supported, it should be avoided. Thanks, user30184! – Howard May 26 '20 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.