<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to get list of views in EGDB in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070455#M61417</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;All the datasets in the PGSQL schema are owned by the connected user so I skipped the datasets removal.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Is this also true for the views? Maybe try it anyway...&lt;/P&gt;&lt;P&gt;I just thought about this: the documentation doesn't say whether it works for views that aren't registered with the database. Have you rgistered your views (I have and don't get errors)?&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Did you try the SQL query from arcpy.ArcSDESQLExecute or from pgAdmin ? The second worked for me.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I used ArcSDESQLExecute, but I work with a Microsoft SQL Server, not PostgreSQL.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 14:36:25 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2021-06-21T14:36:25Z</dc:date>
    <item>
      <title>How to get list of views in EGDB</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070372#M61413</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to create a python script using arcpy.AnalyzeDatasets_management in order to maintain my Enterprise Geodatabase (PostgreSQL).&lt;/P&gt;&lt;P&gt;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&lt;EM&gt; 'Could not analyze dataset &amp;lt;view name&amp;gt;'.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;To this end, I use arcpy.ArcSDESQLExecute to execute this query :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;SELECT table_name as view_name FROM information_schema.views WHERE table_schema not in ('information_schema', 'pg_catalog', 'sde')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The problem I'm facing is that I get the error message &lt;EM&gt;&lt;STRONG&gt;AttributeError: &lt;/STRONG&gt;ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 Invalid pointer argument to function&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;And I don't know how to deal with.&lt;/P&gt;&lt;P&gt;Could you please help me ? Why do I get this error ?&lt;/P&gt;&lt;P&gt;Is there another way to list views ? Or is it possible not get them when listing feature classes ?&lt;/P&gt;&lt;P&gt;Here is my code so far :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;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")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 13:02:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070372#M61413</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2021-06-21T13:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get list of views in EGDB</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070410#M61414</link>
      <description>&lt;P&gt;I don't know why your SQL query fails (it works for me), so I will concentrate on your actual problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Including views in the dataset list doesn't give any errors for me.&lt;/P&gt;&lt;P&gt;I guess you already know the help page, because your code looks very similar (as does mine...), but still:&lt;BR /&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/analyze-datasets.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/analyze-datasets.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Points of notice:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;AnalyzeDatasets can only analyze datasets that are owned by the connected database user!&lt;/LI&gt;&lt;LI&gt;I don't think that function is for relationship classes. At least I got an error when I tried right now.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Try removing the datasets the connected user doesn't own (copied from the help page):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()

# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
    arcpy.env.workspace = os.path.join(workspace,dataset)
    dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()

# reset the workspace
arcpy.env.workspace = workspace

# Get the user name for the workspace
userName = arcpy.Describe(workspace).connectionProperties.user.lower()

# remove any datasets that are not owned by the connected user.
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) &amp;gt; -1]
# more readable:
# userDataList = [ds for ds in dataList if userName in ds.lower()]

# Execute analyze datasets
# Note: to use the "SYSTEM" option the workspace user must be an administrator.
arcpy.AnalyzeDatasets_management(workspace, "NO_SYSTEM", userDataList, "ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 13:23:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070410#M61414</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-06-21T13:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get list of views in EGDB</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070446#M61416</link>
      <description>&lt;P&gt;Thanks Johannes for your answer.&lt;/P&gt;&lt;P&gt;All the datasets in the PGSQL schema are owned by the connected user so I skipped the datasets removal.&lt;/P&gt;&lt;P&gt;I agree that arcpy.AnalyzeDatasets_management is not supposed to deal with Relationship Classes. But as it doesn't produce any error when I list RCs in ArcGIS Pro geoprocessing tool, I kept those RCs in arcpy script.&lt;/P&gt;&lt;P&gt;Did you try the SQL query from arcpy.ArcSDESQLExecute or from pgAdmin ? The second worked for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 14:22:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070446#M61416</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2021-06-21T14:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get list of views in EGDB</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070455#M61417</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;All the datasets in the PGSQL schema are owned by the connected user so I skipped the datasets removal.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Is this also true for the views? Maybe try it anyway...&lt;/P&gt;&lt;P&gt;I just thought about this: the documentation doesn't say whether it works for views that aren't registered with the database. Have you rgistered your views (I have and don't get errors)?&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Did you try the SQL query from arcpy.ArcSDESQLExecute or from pgAdmin ? The second worked for me.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I used ArcSDESQLExecute, but I work with a Microsoft SQL Server, not PostgreSQL.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 14:36:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070455#M61417</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-06-21T14:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get list of views in EGDB</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070480#M61419</link>
      <description>&lt;P&gt;I'm on Oracle (12c) and have a similar problem. My solution was to simply put my analyze datasets (and the rebuild indexes) functions in their own try/except where I pass on the error from the views. However, if it's as simple as registering the views as &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;mentions, I would rather do that.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 15:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070480#M61419</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-06-21T15:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get list of views in EGDB</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070899#M61438</link>
      <description>&lt;P&gt;With the SQL query below, I finally managed to get the views from PGSQL with arcpy.ArcSDESQLExecute :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;SELECT table_name::varchar(100) as view_name FROM information_schema.views WHERE table_schema not in ('information_schema', 'pg_catalog', 'sde')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 11:09:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-list-of-views-in-egdb/m-p/1070899#M61438</guid>
      <dc:creator>OlivierLefevre</dc:creator>
      <dc:date>2021-06-22T11:09:02Z</dc:date>
    </item>
  </channel>
</rss>

