Hello,
I am running a script via the ArcPro python terminal, with the layers I am using in my script open in the project. sTabName is a string which contains the name of the table I have opened in ArcPro.
I have a table which has 200k records, I wish to update and insert <20 items within this table.
I need to firstly use an UpdateCursor to update a few rows, then a InsertCursor to insert some rows to replace those I updated.
My code currently:
# Create a table view to use within the edit session
arcpy.SelectLayerByAttribute_management(sTabName, "NEW_SELECTION", where_clause=sOldWhere)
TableViewCount = int(arcpy.GetCount_management(sTabName).getOutput(0))
print(f"sTabName with sql querey: {sOldWhere}, applied. TableViewCount contains: {TableViewCount} rows")
# Start editing session
edit = None # Initialize edit variable
edit = arcpy.da.Editor(SDE_Workspace_Path)
edit.startEditing(False, True)
edit.startOperation()
# Retire the old assessments
print("Retiring old assessment(s)...")
count = 0
with arcpy.da.UpdateCursor(sTabName, ("RecordStatus", "Retired")) as oRows:
for oRow in oRows:
oRow[0] = "Retired"
sretired = "Title retired & replaced by {0}".format(",".join(aNewSIDs))
if len(sretired) > 250:
oRow[1] = 'Title retired & replaced by Multiple parcels'
else:
oRow[1] = sretired
oRows.updateRow(oRow)
count += 1
print(f"retiring item {count} of {TableViewCount}")
The Problem:
This seems to take a very long time to open up the UpdateCursor, >1-2 minutes, and the search cursor which comes after it (not included in code sample).
How can I improve efficiency given that I am only updating the specific items from where_clause=sOldWhere?
I have tried using:
arcpy.MakeTableView_management(sTable_path, "TableView", where_clause=sOldWhere)
instead of what is at Line 2, which does seem to run faster, but this creates a tableview item which I then have to remove (to clean up) which adds more processing time once again.
I wish to reduce the processing time of this script as much as possible as it is manually run multiple times over a day to complete a task.