Problem Executing arcpy.Select_analysis

2371
2
09-22-2011 06:40 AM
JohanOldekop
New Contributor
Hi,

currently trying to learn Python to do some scripting but unfortunately I keep getting an error message. Below are the scripts I have used, followed by the actual Error Message:

# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "C:/GTZ Data/PEN_IUCN/PEN_IUCN"

# Set local variables
in_features = "AMPHANURA_RBS_Clip"
out_feature_class = "C:/IUCN Data/AMPHANURA/AMPHANURA_RBS_Clip_FID3.shp"
where_clause = '"FID" = \'3\''

# Execute Select
arcpy.Select_analysis(in_features, out_feature_class, where_clause)

AS WELL AS

# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "C:/GTZ Data/PEN_IUCN/PEN_IUCN"

# Set local variables
in_features = "C:/IUCN Data/AMPHANURA/AMPHANURA_RBS_Clip.shp"
out_feature_class = "C:/IUCN Data/AMPHANURA/AMPHANURA_RBS_Clip_FID3.shp"
where_clause = '"FID" = \'3\''

# Execute Select
arcpy.Select_analysis(in_features, out_feature_class, where_clause)

Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 999999: Error executing function. An invalid SQL statement was used. An invalid SQL statement was used. Failed to execute (Select).

Any ideas?

thanks a lot...

Johan
Tags (2)
0 Kudos
2 Replies
MarcNakleh
New Contributor III
Hello Johan,

I think that the main issue here is FID's field type: it is technically of type 'Object ID' which is queried like an integer field.

So a query referencing it would look like:
'"FID" = 3'

without any additional quotes (in contrast to string fields, where you would need those quotes.)

The examples on ArcGIS' Select Analysis page seem to all be referencing string fields, unfortunately. The Building SQL Queries page has more info on how to structure queries, and features a section dealing with searching for numbers.

I hope this helps!
Marc
0 Kudos
JohanOldekop
New Contributor
ran the script with the changes and it worked!

thanks for the help...

Johan
0 Kudos