Bug report #8369
Null propagation of fields in expression based labelling
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Labelling | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | duplicate |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 17146 |
Description
In one of my shapefiles I have an expression based label.
The expression is
"refName" || '\
' || "refDetail" || '\
' || "refSource" || '\
' || "refURL" || '\
' || "refDate"
So it is concatenating five fields in the attribute table along with newlines to format the label.
The problem is that if any of these fields are null, the entire label is not being displayed.
This is presumably from null propagation - one null makes the entire expression result null.
It should be feasible for the expression evaluator to evaluate each field value individually and exclude any nulls from being put into the final result.
Related issues
History
#1 Updated by Nathan Woodrow over 11 years ago
- OS version deleted (
8) - Operating System deleted (
Windows)
String + NULL = NULL. We don't treat NULL as empty string because it's not correct to do so. NULL and empty mean two different things so are treated differently.
The best way to handle this is using the coalesce function
coalesce("refName",'')
If refName is null then a empty string is returned. You expression would look like this:
coalesce("refName",'') || '\
' || coalesce("refDetail",'') || '\
' || coalesce("refSource",'') || '\
' || coalesce("refURL",'') || '\
' || coalesce("refDate" ,'')
You can also use the format function in order to clean that up
format('%1\
%2\
%3\
%4\
%5',coalesce("refName",''), coalesce("refDetail",''), coalesce("refSource",''), coalesce("refURL",''), coalesce("refDate" ,''))
#2 Updated by Jürgen Fischer over 11 years ago
- Resolution set to duplicate
- Status changed from Open to Closed
duplicate of #7510