Tuesday 2 April 2019

arcgis 10.2 - Editing PostgreSQL geodatabase table using ArcPy?


I'm trying to update a table using a python script and it's not working. The table resides in a postgres geodatabase and is versioned. I have also verified my user permissions (I'm the admin). The version is public (i.e. not protected). The table properties show that the current user has select, insert, update, and delete privileges.


Here's my command


with arcpy.da.Editor(arcpy.env.workspace) as edit: 
with arcpy.da.InsertCursor("service", ["service_id"]) as cur:
cur.insertRow([0])


The error:


Runtime error 
Traceback (most recent call last):
File "", line 3, in
RuntimeError: The requested operation is invalid on a closed state [ugdb.sde.service]

Answer



After much exploration, I finally found the solution. It has to do with how your geodatabase is configured and this is not explained in the documentation.


If the tables are versioned with the option to move the edits to the base, THEN you do not use startOperation() and stopOperation(). HOWEVER, if your tables are versioned in the default manner, then you need to control transaction operations explicitly. I can't say I fully understand why this makes a difference, but in my case it was absolutely the solution.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...