Select to view content in your preferred language

Using Python to Rebuild Indexes

546
2
Jump to solution
02-08-2024 05:59 AM
JoshBillings
Frequent Contributor

Hey all,

I am attempting to create a script that rebuilds indexes and updates statistics on tables on a regular schedule. I am using an Oracle enterprise geodatabase.

I am using this post from Esri to try and recreate my script (see the Rebuild indexes and update statistics section): Using Python scripting to batch reconcile and post traditional versions 

When I try and run my code (below), I get this error which is noting the dataList variable as the problem: 

TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType' 

 

workspace = r"A:\File\Path\dataowner.sde"
userName = arcpy.Describe(workspace).connectionProperties.user

dataList = arcpy.ListTables(userName + '.*') + arcpy.ListFeatureClasses(userName + '.*') + arcpy.ListRasters(userName + '.*')

for dataset in arcpy.ListDatasets(userName + '.*'):
    dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)

arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", dataList, "ALL")
arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

 

Thanks - Josh

0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

The error is because the result of ListTables is empty/null. Try setting the environment workspace as shown on the first line of the example in the docs.

 

# set the workspace 
arcpy.env.workspace = r"A:\File\Path\dataowner.sde"

# Set a variable for the workspace
workspace = arcpy.env.workspace

userName = arcpy.Describe(workspace).connectionProperties.user

dataList = arcpy.ListTables(userName + '.*') + arcpy.ListFeatureClasses(userName + '.*') + arcpy.ListRasters(userName + '.*')

for dataset in arcpy.ListDatasets(userName + '.*'):
    dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)

arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", dataList, "ALL")
arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

 

View solution in original post

0 Kudos
2 Replies
BlakeTerhune
MVP Regular Contributor

The error is because the result of ListTables is empty/null. Try setting the environment workspace as shown on the first line of the example in the docs.

 

# set the workspace 
arcpy.env.workspace = r"A:\File\Path\dataowner.sde"

# Set a variable for the workspace
workspace = arcpy.env.workspace

userName = arcpy.Describe(workspace).connectionProperties.user

dataList = arcpy.ListTables(userName + '.*') + arcpy.ListFeatureClasses(userName + '.*') + arcpy.ListRasters(userName + '.*')

for dataset in arcpy.ListDatasets(userName + '.*'):
    dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)

arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", dataList, "ALL")
arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")

 

0 Kudos
JoshBillings
Frequent Contributor

I completely overlooked that. Thanks @BlakeTerhune!

0 Kudos