SQL syntax for Extract by Attributes with "OR" operator error

367
1
01-18-2013 08:47 AM
AnneRiddle
New Contributor
Hi all,

I am trying to write a Python code block using Extract by Attributes with a SQL query including the "OR" operator that consistently will not work regardless of the syntax I try. As it is the code block looks like this:

for raster in arcpy.ListRasters(): 
    outpoint = raster + "af"
    extract = arcpy.sa.ExtractByAttributes (raster, "/\VALUE/\ = 6 OR /\VALUE/\ = 8")
    extract.save (outpoint)


The SQL syntax is directly copied from the Results window, which ran successfully, but throws an error (at the end below) when run in IDLE. I had originally been using the option here (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000) to escape the double interior quotes with slashes, which did not throw an error but did not extract correctly (it extracted values of 2 and 0 in addition to 6 and 8). I've also tried enclosing the string in triple quotes or escaping the single interior quotes, which both threw errors; IDLE did not recognize the string using the escaping-interior-quotes syntax.

Any help would be appreciated.

Traceback (most recent call last):
  File "S:\FIRE\gdb.py", line 32, in <module>
    extract = arcpy.sa.ExtractByAttributes (raster, "/\VALUE/\ = 6 OR /\VALUE/\ = 8")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1117, in ExtractByAttributes
    where_clause)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Utils.py", line 47, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\sa\Functions.py", line 1113, in wrapper
    out_raster)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in <lambda>
    return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used. [VAT_u01002020]
An invalid SQL statement was used. [SELECT * FROM VAT_u01002020 WHERE /\VALUE/\ = 6 OR /\VALUE/\ = 8]
Failed to execute (ExtractByAttributes).
Tags (2)
0 Kudos
1 Reply
AnneRiddle
New Contributor
Just an update: I also tried with this syntax:

extract = arcpy.sa.ExtractByAttributes (raster, "\VALUE\ = 6 OR \VALUE\ = 8"


And received a different error, this time:

An expected Field was not found or could not be retrieved properly.
An expected Field was not found or could not be retrieved properly. [VAT_u01002020]
Failed to execute (ExtractByAttributes).


Which is also a SQL syntax problem.
0 Kudos