First of all I've successfully used the "selectbyexpression" tool to UN-SELECT points by setting its 3rd parameter to "2" in the following script:

Input = QgsMapLayerRegistry.instance().mapLayersByName('Central_Region_civic_pts')[0]
clear_expression = '"STRNAME" = '+"'"+"Main"+"'"
processing.runalg('qgis:selectbyexpression', Input, clear_expression, 2)

But now I want to write an expression that will unselect EVERYTHING, not just a particular street by name (e.g. "MAIN"). This will be useful near the start of my script to wipe the slate clean, just in case anything is already selected, before my script goes on to make the selections I actually want.

Since my 'Input' file has a "PID" column ("Property ID", all numbers) I figured something like the following would work:

clear_expression = '"PID" > 0'

But it doesn't.


I suspect the problem is with the ">" symbol. Can anyone confirm this, and suggest a workaround or another tool to do the job?

I also suspect there's nothing unique about the ">" symbol. I'll bet there are more operator symbols than ">" that also don't work with this tool because the "Select By Expression" GUI at the top menu of QGIS only has 9 operator options at the top and ">" isn't one of them. Neither is "<". And there's no option for "does not equal" either, etc, etc...

enter image description here

  • In SQL, <> means "does not equal" - see w3schools.com/sql/sql_where.asp Commented Oct 30, 2015 at 23:45
  • Yes, useful in SQL. Unfortunately doesn't appear to be an option in QGIS's "selectbyexpression" GUI or by scripting.
    – Waterman
    Commented Oct 31, 2015 at 0:34

2 Answers 2


How about this, where Input is your layer object?


see: How to remove all selection from all registered layers using QGIS plugin?

  • Thanks @pauloraposo, this proves to be the most elegant solution so far!
    – Waterman
    Commented Oct 31, 2015 at 13:04

Could you do a 'create new selection' that chooses to select something that will definitely result in zero results?

  • I certainly could @Koshy Thomas. That did the trick, thanks loads! Too bad Q doesn't have more operators available but perhaps in future versions.
    – Waterman
    Commented Oct 30, 2015 at 23:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.