11

I'm trying to make a style based on rules, and I want to use a boolean field I have created for that.

But I do the following:

"field" like 'TRUE'
"field" like TRUE
"field" like 1
"field" like '1'

and nothing is selected.

How can I select true values in a boolean field then? I'm using QGIS reading from PostGIS database.

4
  • 1
    Would you be able to edit your question to include the GIS software that you are using, please ?
    – PolyGeo
    Commented May 25, 2015 at 20:11
  • 4
    I don't think the boolean field supports the like operator, try "field" = 1 instead. Commented May 25, 2015 at 21:18
  • What data source are you using? QGIS doesn't even support creating bool fields in new Shapefiles or Spatialite afaik.
    – underdark
    Commented May 25, 2015 at 21:54
  • Sorry: I'm using a postGIS database
    – exodehm
    Commented May 25, 2015 at 22:06

3 Answers 3

8

When using a boolean, you need to use the IS operator instead of LIKE. So your expression should be:

"field" is true

However, since you want to select the fields which are TRUE, you can also shorthen this and use this expression:

"field"

This works because in QGIS the fields will be selected, where the used expression returns TRUE. So on a booleanfield it is enough when the content is TRUE and therefore returning TRUE when evaluating it.

Proof:

enter image description here

1
  • For some reason "is true" wouldn't work for me, but just the "field" option did.
    – Foggy
    Commented Oct 3, 2023 at 23:04
4

I would recommend, in order to see how QGIS views the values, to use the "all unique" button.

You should get a list of values.

enter image description here

4

Finally I have found the solution:

"field" like 't'

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.