Using ArcGIS Pro 2.9.5 I found that ArcSDESQLExecute is not able to handle unique identifiers in a table.
I tried to run the following Script:
database = 'C:\\Installation\\updm.sde'
egdb_conn = arcpy.ArcSDESQLExecute(database)
sql_clause = "SELECT PROJECT_ID from DataOwner.My_PROJECTS;"
print(sql_query)
query_return = egdb_conn.execute(sql_clause)
len(query_return)
the table My_PROJECTS has a column PROJECT_ID defined as a uniqueidentifier., the result odf the execution is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
In [39]:
Line 12: query_return = egdb_conn.execute(sql_clause)
File C:\ArcGISPro\Resources\ArcPy\arcpy\arcobjects\arcobjects.py, in execute:
Line 44: return convertArcObjectToPythonObject(self._arc_object.Execute(*gp_fixargs(args)))
AttributeError: ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 Invalid pointer argument to function
Solved! Go to Solution.
Despite the fact that unique identifiers are supported, I went for a casting approach
database = 'C:\\Installation\\updm.sde' egdb_conn = arcpy.ArcSDESQLExecute(database) # Getting the ID's froma table sql_clause = "SELECT CAST(PROJECT_ID AS VARCHAR(100)) from DataOwner.My_PROJECTS;" query_return = egdb_conn.execute(sql_clause) # Whatever operation you want to do with the results, in this case # is just the verification of how many results, but they will be # iterated later len(query_return)
* by the way the semicolon does not make any difference.
Try without the ending semicolon in the SQL statement.
Thanks for the suggestion.
As a matter of fact I did it before of making the post, but I did it again just to be able to copy and paste the output from the execution:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
In [48]:
Line 7: query_return = egdb_conn.execute(sql_clause)
File C:\ArcGISPro\Resources\ArcPy\arcpy\arcobjects\arcobjects.py, in execute:
Line 44: return convertArcObjectToPythonObject(self._arc_object.Execute(*gp_fixargs(args)))
AttributeError: ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 Invalid pointer argument to function
---------------------------------------------------------------------------
As I already state in my original post this happens with columns defined as unique identifier. If I try to make the query to an INT, VARCHAR or DECIMAL column, the query is performed with out any issues.
Despite the fact that unique identifiers are supported, I went for a casting approach
database = 'C:\\Installation\\updm.sde' egdb_conn = arcpy.ArcSDESQLExecute(database) # Getting the ID's froma table sql_clause = "SELECT CAST(PROJECT_ID AS VARCHAR(100)) from DataOwner.My_PROJECTS;" query_return = egdb_conn.execute(sql_clause) # Whatever operation you want to do with the results, in this case # is just the verification of how many results, but they will be # iterated later len(query_return)
* by the way the semicolon does not make any difference.