Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

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

$
0
0
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:

Code:

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/arcgisdesk...00000071000000) 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.

Code:

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).


Viewing all articles
Browse latest Browse all 2485

Trending Articles