In QGIS 2.14.11 LTR I have to apply the same (or similiar) filter query to various layers. I have the road name to filter for in a project variable and try to apply the following query:
"road_name" = @current_road
This works as expected in a 'select by expression', but returns 0 row as a filter query, where I obviously have to use
"road_name" = 'the road name'
As variables are obviously not evaluated in filter queries, is there a deeper reason for this that I don't see, and is there another way/syntax to use variables in filter queries?
2 Answers 2
Layer filters don't use QGIS expressions, and are instead handed directly off to the underlying data provider. So, for instance, a filter on a postgis layer is passed to postgres to evaluate, and accordingly must use postgres syntax and functions. This means QGIS expressions functions and features like variables don't work in layer filters.
ndawson is correct. You can use variables though in styling rules. This will help specifically if you only want to filter layers for showing or printing.
Explore related questions
See similar questions with these tags.