9

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?

asked Feb 18, 2017 at 11:39

2 Answers 2

11

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.

answered Feb 18, 2017 at 20:23
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.

answered Feb 21, 2017 at 18:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.