Skip to content

concat() returns NULL when all arguments are NULL: it should return an empty string #65808

Description

@Oisin-JK

What is the bug or the crash?

####EDITED following discussion with @agiudiceandrea
concat() returns NULL when all arguments are NULL: it should return an empty string see screenshot at comment below

In addition, Preview of the expression result (bottom left corner of expression builder dialog) reports an empty string when concat() returns a NULL value.

####ORIGINAL
strpos("myattribute",'Fell')=True returns NULL when "myattribute" = NULL.
This is undesirable (it should return 0) but understandable.

But in my user case I am using three concatenated fields for the haystack, which converts NULL to empty strings. But
strpos(concat(work1, work2, work3),'Fell') still returns NULL if work1, work2 and work3 are all NULL. I have checked and concat(work1, work2, work3) returns an empty string if if work1, work2 and work3 are all NULL.

Steps to reproduce the issue

Creat a layer (temporary point layer is fine)
Add text fields myfield1 and myfield2
Add 3 features.
In feature 1 leave or set value of myfield1 and myfield2 to Null
In feature 2 leave or set value of myfield1 to 'a' and myfield2 to Null
In feature 3 leave or set value of myfield1 to 'Fell' and myfied2 to Null

Create an Advanced Filter Expression
For the expression enter strpos(concat(myfield1, myfield2),'Fell')

This expresion will return NULL for feature 1, 0 for feature 2 and 1 for feature 3.
This expresion SHOULD return 0 for feature 1, 0 for feature 2 and 1 for feature 3.

Versions

QGIS version3.44.8-Solothurn
QGIS code revisiond25052deb8b
 
Libraries
Qt version5.15.13
Python version3.12.13
GDAL version3.12.2 (Compiled)
3.12.3 (Running) — Chicoutimi
PROJ version9.8.0 (Compiled)
9.7.1 (Running)
EPSG Registry database versionv12.029 (2025-10-03)
GEOS version3.14.1-CAPI-1.20.5
SQLite version3.50.4
PDAL version2.10.0
PostgreSQL client version17.3
SpatiaLite version5.1.0
QWT version6.3.0
QScintilla2 version2.14.1
OS versionWindows 10 Version 2009
 
Active Python plugins
AnotherDXF2Shape1.4.2
GeoCoding2.19
magic_map_loader1.2
processing_saga_nextgen1.1.0
processing_umep2.2.8
qfieldsyncv4.18.3
quick_map_services1.1.0
splitmultipart1.0.0
db_manager0.1.20
processing2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

No Duplicate of the Issue

  • I have verified that there are no existing issues raised related to my problem.

Additional context

No response

Metadata

Metadata

Assignees

Labels

BugEither a bug report, or a bug fix. Let's hope for the latter!ExpressionsRelated to the QGIS expression engine or specific expression functions

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions