My goal is to select all of the features in a layer with certain names.

I have a list of 86 Subdivision names and a I am using a county Subdivision dataset, the names in the dataset include the subdivision names but also some text before and after the name (i,e. REPLAT, and PLAT 1, etc).

I created an expression to return the names from my list but it is displaying the following parser errors in QGIS (my query is displayed in the image as well).

QGIS Parser Error

Query text (sample):

FROM 'SUBDIVISION_POLYGON_614b57b6_a27b_4aaa_973c_aa7da31cedd6' 
WHERE "PLAT_NAME1"  = 'austinbrooke acres%' OR
'%austintown park%' OR
'%beverly hill%' OR
'%bridget heights%' OR
'%broadview%' OR
'%burgess run heights%' OR
'%candywoods estates%' OR...

What do these errors mean? Can this work or is another approach better?

  • 4
    You can't type SQL as a QGIS Expression. You can use SQL in Virtual Layers (beware, in SQL, you must repeat the field for all the OR statement). – J. Monticolo Dec 6 '19 at 17:49
  • Let me know if my answer solves your issue. I don't use wildcard characters often enough to know it they're set up right. I notice that the first term '&austinbrooke acres%' starts with an ampersand (&) when all the other terms start with the percent symbol (%). Not sure if that's intentional or not. – csk Dec 6 '19 at 18:34

You're doing a lot more work than necessary for the select by expression tool. There's no need to tell QGIS to "select" because the tool already does that. And there's no need to specify the layer name, 'SUBDIVISION_POLYGON_614b57b6_a27b_4aaa_973c_aa7da31cedd6', because you're presumably running the tool on that layer. (To specify which layer to run this tool on, select that layer in the Layer panel.)

Instead, the expression should be a statement of fact, which will evaluate to either 'true' or 'false'. QGIS will iterate through the features in the current layer, analyze the veracity of that statement for each feature, and select the features when the statement evaluates to true.

Another issue is the way your or statements are set up - you can't string together multiple conditions like that. Sorry I don't know the technical coding terms to describe what I mean. Hopefully this example makes it clear: it should be "a" = 'a' or "a" = 'b', not "a" = 'a' or 'b'

Instead, try:

"PLAT_NAME1"  = '&austinbrooke acres%' OR
"PLAT_NAME1"  = '%austintown park%' OR
"PLAT_NAME1"  = '%beverly hill%' OR
"PLAT_NAME1"  = '%bridget heights%' OR
"PLAT_NAME1"  = '%broadview%' OR
"PLAT_NAME1"  = '%burgess run heights%' OR
"PLAT_NAME1"  = '%candywoods estates%' OR...

Or try this more efficient expression:

"PLAT_NAME1" IN ('&austinbrooke acres%', '%austintown park%', '%beverly hill%','%bridget heights%', '%broadview%', '%burgess run heights%', '%candywoods estates%', ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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