Skip to main content
3 of 4
added 225 characters in body
Matthias Kuhn
  • 28.2k
  • 3
  • 89
  • 130

Update Please read this answer for a safer method of achieving the same http://gis.stackexchange.com/a/74940/9839

In case you experience performance issues you may still resort to original method described below.

The only way of forwarding a WHERE clause to the data provider (backend) at the moment is to use the setSubsetString method of QgsDataProvider

If you have a QgsVectorLayer assigned to a variable vl :

vl.setSubsetString( 'Counties = "Norwich"' )

This causes heavy side-effects, because the filter will then apply to the whole layer and not only to your query, so you have to carefully consider if this is really an option for your use case!

Any other option will require a seperate connection to the database or adding a new layer with a subsetString as outlined above.

Matthias Kuhn
  • 28.2k
  • 3
  • 89
  • 130