7

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?

1

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.

6

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.

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.