Select to view content in your preferred language

SearchCursor sql_clause not working

679
3
Jump to solution
09-14-2022 06:29 AM
mmann1123
Occasional Contributor

I am working with searchcursors for a .shp file with arcpy 3.0-py39. I am unable to get the searchcursor's sql clause to do frankly anything. Regardless of my clause I get the same result (all rows printed to screen, unordered).

For instance both of these provide the same response:

for row in arcpy.da.SearchCursor(in_table="Crashes_in_DC",
              field_names="Tot_PedBik",
              sql_clause=('TOP 3', None)):
        print(f" {row[0]}" )

 

for row in arcpy.da.SearchCursor(in_table="Crashes_in_DC",
              field_names="Tot_PedBik",
              sql_clause=(None, 'ORDER BY Tot_PedBik DESC')):
        print(f" {row[0]}" )

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
dgiersz_cuyahoga
Frequent Contributor

I don't think you can use either of those SQL queries against a shapefile (see Example 5a & 6): https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm

May have better luck using the where_clause with shapefiles.

#CLE #sloth

View solution in original post

3 Replies
dgiersz_cuyahoga
Frequent Contributor

I don't think you can use either of those SQL queries against a shapefile (see Example 5a & 6): https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm

May have better luck using the where_clause with shapefiles.

#CLE #sloth
mmann1123
Occasional Contributor

Ok I will try that.

0 Kudos
mmann1123
Occasional Contributor

They could at least throw a warning my way though...

0 Kudos