Hello,
I have two questions, firstly about using SelectByAtribute_managementm and secondly why my selection won't work with my updateCursor. I apologise for the bad formatting below.
I am using:
arcpy.SelectLayerByAttribute_management(sTable_path, "NEW_SELECTION", sOldWhere)
to select 2 records from a 200k+ table of records. Those which match the SQL statement within sOldWhere
I wish to double check the correct items are selected, I am using:
selection_count = int(arcpy.GetCount_management(sTable_path).getOutput(0))
This returns a count of 200k+, which is incorrect. The SQL statement is valid. It should have two items selected.
If I save the output of the SelectLayerByAttribute_management to a variable via:
itemsToRetire, itemsToRetireCount = arcpy.SelectLayerByAttribute_management(sTable_path, "NEW_SELECTION", sOldWhere)
I can either print out itemsToRetireCount, or run getCount_management on itemsToRetire to get a result of 2, as expected.
What is going on?
Secondly and some more context, I am accessing a large table via sde connection.
I wish to then run an update cursor on the (2) selected table items, but using the itemsToRetire variable in this update cursor does not seem to work. It hangs and eventually says the table cannot be updated.
sTable_path contains the full path to the actual table, going through a sde connection.
SDE_Workspace_Path contains just the path to the SDE connection, not including the specific table
Here is a overview of the code, I have set up an edit session before accessing sTablePath using:
edit = arcpy.da.Editor(SDE_Workspace_Path) #opening workspace path
edit.startEditing(False, True)
edit.startOperation()
try:
itemsToRetire, itemsToRetireCount = arcpy.SelectLayerByAttribute_management(sTable_path, "NEW_SELECTION", sOldWhere)
#selection_count = int(arcpy.GetCount_management(sTable_path).getOutput(0))
print(f"!!!Selected {itemsToRetireCount} items for update using where clause: {sOldWhere}!!!")
...
with arcpy.da.UpdateCursor(itemsToRetire, ("X", "Y")) as oRows:
but my update cursor won't work, and has a generic error of, cannot update table.
Thanks.