<?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: Accessing a POSTGRES database from a stand alone python script in Geodatabase Questions</title>
    <link>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009390#M6905</link>
    <description>&lt;P&gt;It would help if you provide the Python code you are using, and specify whether the PG database is enterprise geodatabase enabled.&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;</description>
    <pubDate>Mon, 14 Dec 2020 18:47:25 GMT</pubDate>
    <dc:creator>VinceAngelo</dc:creator>
    <dc:date>2020-12-14T18:47:25Z</dc:date>
    <item>
      <title>Accessing a POSTGRES database from a stand alone python script</title>
      <link>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009303#M6904</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a python process that I am converting from Oracle to POSTGRES and I seem to be having issues accessing the POSTGRES database multiple times in the same python action.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I can run a search cursor on a table inside the POSTGRES database one time and get results (this search cursor is executed with a WITH clause). when I try to run another search cursor on the same table i get a RUNTIME error.&lt;/P&gt;&lt;P&gt;If I skip the second cursor and move along in my process I get another RUNTIME error when I attempt an &lt;STRONG&gt;arcpy.da.Walk&lt;/STRONG&gt; on the database itself.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To me, and I am a complete novice, it seems like accessing the database multiple times is causing the error, perhaps because of some sort of lock placed on it by POSTGRES.&lt;/P&gt;&lt;P&gt;If anyone has any advice i would apricate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;here is a search cursor function that works every time i run it in my python script. this is the first time the database is accessed.&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;def _select_rows_from_table(self, sde_connection_path, table_name, fields, where_clause):
   
    row_array = []

    with arcpy.da.SearchCursor(os.path.join(sde_connection_path, table_name), fields, where_clause) as table_cursor:
        for a_row in table_cursor:
            row = dict()
            idx = 0
                
            for field_name in fields:
                row[field_name] = a_row[idx]
                idx = idx + 1
                
            row_array.append(row)

    return row_array&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I have tried to run many different functions after this and I always get a runtime error. here is an example of one that does not work. the workspace passed is the exact same as the one passed in the first function.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    def _get_table_mapping(self, workspace):
        mapping = dict()
        feature_datasets = list()
        feature_datasets.append(None)
        dataset_walker = arcpy.da.Walk(workspace, datatype=['FeatureDataset'])
        for unused1, feat_datasets, unused2 in dataset_walker:
            for fds in feat_datasets:
                feature_datasets.append(fds)
        for a_feat_dataset in feature_datasets:
            wspace = workspace

            if a_feat_dataset is not None:
                wspace = os.path.join(workspace, a_feat_dataset)

            walker = arcpy.da.Walk(wspace, datatype=['FeatureClass', 'Table'])

            for junk1, junk2, things in walker:
                for a_thing in things:
                    pieces = a_thing.split('.')
                    base_name = pieces[len(pieces) - 1].lower()
                    mapping[base_name] = a_thing

        return mapping&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;it may also help to know that i can execute all of these against the POSTGRES database inside of ArcGIS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also as far as I know the database is geodatabse enabled. I can see all of the features in ArcGIS and have published a few services against the data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 20:02:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009303#M6904</guid>
      <dc:creator>DavidMetzler1</dc:creator>
      <dc:date>2020-12-14T20:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a POSTGRES database from a stand alone python script</title>
      <link>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009390#M6905</link>
      <description>&lt;P&gt;It would help if you provide the Python code you are using, and specify whether the PG database is enterprise geodatabase enabled.&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 18:47:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009390#M6905</guid>
      <dc:creator>VinceAngelo</dc:creator>
      <dc:date>2020-12-14T18:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing a POSTGRES database from a stand alone python script</title>
      <link>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009470#M6908</link>
      <description>&lt;P&gt;I have modified my question based on your suggestions, thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 21:21:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/geodatabase-questions/accessing-a-postgres-database-from-a-stand-alone/m-p/1009470#M6908</guid>
      <dc:creator>DavidMetzler1</dc:creator>
      <dc:date>2020-12-14T21:21:00Z</dc:date>
    </item>
  </channel>
</rss>

