QGIS – Differences in Query Syntax Between Attribute Table and Feature Filter in QGIS

expressionfilterqgisquery

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?

Best Answer

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.

Related Question