Hello,
I'm trying to create a python script using arcpy.AnalyzeDatasets_management in order to maintain my Enterprise Geodatabase (PostgreSQL).
When listing thef eature classes I also get the views I created in the EGDB and arcpy.AnalyzeDatasets_management provide me with error messages like 'Could not analyze dataset <view name>'.
As I don't know if the tool fails about the entire dataset list or only about those views, I decided to remove those views from the list I provide arcpy.AnalyzeDatasets_management with.
To this end, I use arcpy.ArcSDESQLExecute to execute this query :
SELECT table_name as view_name FROM information_schema.views WHERE table_schema not in ('information_schema', 'pg_catalog', 'sde')
The problem I'm facing is that I get the error message AttributeError: ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 Invalid pointer argument to function.
And I don't know how to deal with.
Could you please help me ? Why do I get this error ?
Is there another way to list views ? Or is it possible not get them when listing feature classes ?
Here is my code so far :
import arcpy
import os
# Set the workspace environment
workspace = r"path_to\my_egdb_connector.sde"
arcpy.env.workspace = workspace
# Get a list of all the datasets the user has access to.
# First, get all the stand alone Tables, Feature Classes and Rasters.
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()
# Get a list of all stand alone Relationship Classes and add them to the master list
dataList += [c.name for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"]
# Next, for feature datasets get all of the Feature Classes and Relationship Classes and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
arcpy.env.workspace = os.path.join(workspace, dataset)
FCs = arcpy.ListFeatureClasses()
RCs = [c.name for c in arcpy.Describe(arcpy.env.workspace).children if c.datatype == "RelationshipClass"]
dataList += FCs + RCs
# Reset the workspace
arcpy.env.workspace = workspace
# Finally, get a list of all views and delete them from the master list
# Connect to the GDB
egdb_conn = arcpy.ArcSDESQLExecute(workspace)
#### HERE COMES THE PROBLEM ####
#Execute SQL
sql = r"select table_name as view_name from information_schema.views where table_schema not in ('information_schema', 'pg_catalog', 'sde')"
egdb_return = egdb_conn.execute(sql)
location_in_egdb = arcpy.Describe(workspace).connectionProperties.database + "." + arcpy.Describe(workspace).connectionProperties.user.lower() + "."
if isinstance(egdb_return, str):
views = [location_in_egdb + egdb_return]
elif isinstance(egdb_return, list):
views = [location_in_egdb + i[0] for i in egdb_return]
dataList = [data for data in dataList if data not in views]
# Execute analyze datasets
arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", dataList, "ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE")