Bug report #5244

Expressions: tostring() does not work as expected when the argument is evaluated to NULL

Added by Giuseppe Sucameli over 12 years ago. Updated over 11 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:-
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed
Crashes QGIS or corrupts data:No Copied to github as #:14979

Description

As far as expression uses 3 logic states (true, false, null) the only way to print strings concatenated to a field is to check if the field is NULL using a CASE statement.

IMHO would make sense to change the tostring() function to return an empty string when the argument is a NULL value.
Maybe would be even better to add an overload of the function tostring(val, defaultval) where the second arg is the default value returned in case of NULL.

History

#1 Updated by Paolo Cavallini about 12 years ago

  • Target version set to Version 2.0.0

#2 Updated by Nathan Woodrow over 11 years ago

I don't like the idea of treating NULL as an empty string. Empty strings are still valid data where as NULL is nothing. NULL might mean N/A for my data vs '' having some meaning. Treating them the same could have bad side effects for people trying to label, style, their data.

You no longer need to use CASE and can use coalesce(COLA, ''). You can also use the new format function which will auto convert to strings

format('%1 %2', coalesce(COLA, ''), coalesce(COLB, ''))

#3 Updated by Nathan Woodrow over 11 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

Also available in: Atom PDF