I am working on a script that is attempting to use ORDER BY. The results I'm seeing are unordered. I've dug quite a bit in GeoNet and elsewhere to no avail. My data is in a FGBD, my understanding is ORDER BY should work...
I'm hoping that there is something wrong with the logic in my script, and someone might help me identify it.
In a nutshell the script selects a group of features based on FEAT_SEQ, the selection is then sorted by a RANK field (NOT WORKING), the first row is then written to a new feature class. All of this is working except for the ordering. The output simply writes the first row, unsorted.
- The TableSelect, selects features in a FC by the FEAT_SEQ field. The FEAT_SEQ is a result of the identify duplicate tool.
- This selection is intended to be "sorted" by the ORDER BY using the SearchCursor
- Finally the first row is written to a new FC
Seq_Count = 0
for i in range(5):
Seq_Count = Seq_Count + 1
Where = "FEAT_SEQ =" + str(Seq_Count)
print("Looping Seq
arcpy.TableSelect_analysis(DUPES, Out, Where)
with arcpy.da.SearchCursor(Out, field_names = fieldnames, sql_clause = (None, 'ORDER BY RANK')) as searchCursor:
with arcpy.da.InsertCursor(winnerTable, fieldnames) as iCur:
row = next(searchCursor)
iCur.insertRow(row)
result = arcpy.GetCount_management(winnerTable)
print('{} has {} records'.format(winnerTable, result[0]))
The sql_clause is on line 9 (shown below)
with arcpy.da.SearchCursor(Out, field_names = fieldnames, sql_clause = (None, 'ORDER BY RANK')) as searchCursor:
screenshot of same code (in case it is easier to read)
Thanks in advance for any insights anyone has to offer!