2

I'm trying to change a field value by the next conditional SQL script from a PostGIS database in QGIS Field Calculator:

case
when "Field_1" = 'YES' then "Field_2" = 'True'
else "Field_2" = 'False'
end

but it returns NULL value.

I've tried with 't'and 'true' as well but it didn't work.

Is there anyone who knows how to solve it?

  • 2
    Try updating existing field "Field_2" with formula "Field_1"='YES', which will evaluate to true or false. Or change 'True' to TRUE and 'False' to FALSE – BERA Jun 20 at 7:23
  • 2
    Note that often 'True' is the literal string "True", whereas True is the boolean value of truth. – til_b Jun 20 at 7:45
6

If you update a field in QGIS Field calculator, just specify the value, don't then "Field_2" = something, just then something.

For your code, try :

CASE
  WHEN "Field_1" = 'YES' THEN True
  ELSE False
END
  • If this is a string field, shouldn't it be 'true' and 'false' (with single quotation marks)? Or will the expression builder understand true and false should be used as strings? – csk Jun 20 at 15:48
  • they both worked as I tested them in a boolean virtual field. I guess as you do that if it's a string field 'true' or 'false'should come between quotation marks – Rodrigo Vargas Jun 20 at 15:57

Your Answer

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

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