11

Using QGIS 2.16.2, I can successfully select records from a shapefile attribute table using the following expression:

left("start_time", 10) = '2015-08-01'

Please note that start_time is a string field.

However, when I copy and paste the same expression into the shapefile's Layer Properties>General>feature filter>Query Builder I get the following error:

enter image description here

I would expect that the same expression would work everywhere in QGIS. What am I doing wrong?

Matthias Kuhn
28.4k3 gold badges92 silver badges133 bronze badges
asked Sep 29, 2016 at 5:49

1 Answer 1

16

Your observation is correct, The Query Builder does not use the same syntax as the rest of QGIS.

Throughout QGIS, the syntax is based on QGIS Expressions a customized SQL dialect. This is portable between almost all parts of QGIS where you can enter a filter, calculate a value... This syntax is parsed and evaluated directly in QGIS (and parts of it may be sent to the provider sometimes).

The provider feature filter defined via query builder (also often referred to as subset string) for the layer works different in the way that QGIS does not look at it at all. All it does is send it to the provider. In this case the provider is OGR which only supports a subset of the SQL syntax but sometimes it's very powerful, e.g. when accessing a postgres/postgis database.

answered Sep 29, 2016 at 6:05
1
  • 1
    Good to know. I used the following query in the filter, and it correctly replaced the selection that I previously tried: "start_time" LIKE '2015年08月01日%' Commented Sep 29, 2016 at 6:20

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.