<?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: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124382#M9677</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Are you sue there is no lock on the table when you were trying to run the update cursor (you aren't looking at it in ArcCatalog, etc. at the same time you are trying to run your update)?&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Can you execute this line successfully: arcpy.da.UpdateCursor(table_to_update, ["*"]). If so, maybe it's an issue with your specified field name?&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Apr 2013 15:34:00 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2013-04-02T15:34:00Z</dc:date>
    <item>
      <title>Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124381#M9676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm working with the arcpy.da module for the first time and just trying to get a handle on how it operates.&amp;nbsp; I have a PostgreSQL database with a simple table that includes these fields:&amp;nbsp; id, field1, field2, field3, field4. At this point the table is not registered with the geodatabase or SDE (I want to do simple unversioned table edits).&amp;nbsp; For the most part I've been trying to follow the ArcGIS 10.1 help examples.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been able to successfully use arpy.da.SearchCursor to list records.&amp;nbsp; This works:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# List records using search cursor (snippet) table_to_select_from = r"/home/engine/scripts/connections/ARCSDE101-DEV1-PG-DC-GDRS_DEV-GDRS-DEFAULT.sde\gdrs_dev.gdrs.test_arcpy_da" field_list = ["id", "field1", "field2", "field3", "field4"] try: &amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(table_to_select_from, field_list) as search_cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in search_cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("{0}, {1}, {2}, {3}, {4}".format(row[0], row[1], row[2], row[3], row[4])) except Exception as err: &amp;nbsp;&amp;nbsp;&amp;nbsp; print(err) &amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can also successfully insert new records using arcpy.da.InsertCursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Insert record (snippet): table_to_insert_into = r"/home/engine/scripts/connections/ARCSDE101-DEV1-PG-DC-GDRS_DEV-GDRS-DEFAULT.sde\gdrs_dev.gdrs.test_arcpy_da" field_list = ["field1", "field2", "field3", "field4"] values_list = ["Test arcpy.da.insertRow", "Hello World!", 10, "2013-03-23"] try: &amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(table_to_insert_into, field_list) as insert_cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert_cursor.insertRow(values_list) except Exception as err: &amp;nbsp;&amp;nbsp;&amp;nbsp; print(err) &amp;nbsp;&amp;nbsp;&amp;nbsp; exit(1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So far so good.&amp;nbsp; However when I attempt to update rows, I cannot successfully create an update cursor.&amp;nbsp; The exception message: "create cursor has failed" is returned.&amp;nbsp; I'm sure this is something simple, but I've been banging my head on it and hope you can help point me in the right direction. In this example I attempt to multiply the value in an integer field by 2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;table_to_update = r"/home/engine/scripts/connections/ARCSDE101-DEV1-PG-DC-GDRS_DEV-GDRS-DEFAULT.sde\gdrs_dev.gdrs.test_arcpy_da" field_list = ["field3"] try: &amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(table_to_update, field_list) as update_cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in update_cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0] = row[0] * 2 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; update_cursor.updateRow(row) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row, update_cursor except Exception as err: &amp;nbsp;&amp;nbsp;&amp;nbsp; print(err)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the string object err which is printed is:&amp;nbsp; "create cursor has failed"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried placing this block inside an arcpy.da.Editor block, but no change in the error result.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts?&amp;nbsp; Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 15:23:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124381#M9676</guid>
      <dc:creator>HalWatson</dc:creator>
      <dc:date>2013-04-02T15:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124382#M9677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Are you sue there is no lock on the table when you were trying to run the update cursor (you aren't looking at it in ArcCatalog, etc. at the same time you are trying to run your update)?&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Can you execute this line successfully: arcpy.da.UpdateCursor(table_to_update, ["*"]). If so, maybe it's an issue with your specified field name?&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 15:34:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124382#M9677</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2013-04-02T15:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124383#M9678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you, this is helpful.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) I don't believe there are any locks on the table.&amp;nbsp; ArcMap, PgAdmin are both closed and I checked on the database cluster from the back end and there are no connections to this database prior to running the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Your code worked.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3)&amp;nbsp; I definitely have a field called "field3" in my table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's what I did to test your idea.&amp;nbsp; I commented out my code block and ran this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.UpdateCursor(table_to_update, ["*"])
except Exception as err:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(err)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and did not get an error returned.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So then I tried reformatting that into a &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;with&lt;/SPAN&gt;&lt;SPAN&gt; block which is how I was doing it before:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(table_to_update, ["*"]) as update_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
except Exception as err:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print(err)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which also does not return an error.&amp;nbsp; Hurray!. So I thought I would step down one more level using ["*"] like you did.&amp;nbsp; I'm not sure using &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;pass&lt;/SPAN&gt;&lt;SPAN&gt; is OK here, but I thought it was worth trying:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(table_to_update, ["*"]) as update_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in update_cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp; except Exception as err:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(err)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this block returns the error:&amp;nbsp; create cursor has failed&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just to check that I hadn't put a lock on the table somehow, I re-ran the 2nd block above again and it still got no error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again, I'm learning.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:07:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124383#M9678</guid>
      <dc:creator>HalWatson</dc:creator>
      <dc:date>2021-12-11T07:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124384#M9679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure what's going on exactly, but some ideas that might help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Ditch the "with" statement stuff... I think this was implemented by ESRI to reduce confusion about cursorsstill retaining a lock on the database upon failure. It's nice, but not critical... I do not use it... but maybe I should... Anyway the more simple "old way" syntax is then something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;updateRows = arcpy.da.UpdateCursor(myTbl, ["MY_FIELD"])
for updateRow in updateRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldValue = updateRow[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; field value = fieldValue + 10
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)
del updateRow, updateRows&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. This might be useful info: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/70773-Row-objects-in-the-Data-Access-module?p=248106&amp;amp;viewfull=1#post248106" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/70773-Row-objects-in-the-Data-Access-module?p=248106&amp;amp;viewfull=1#post248106&lt;/A&gt;&lt;SPAN&gt;. It presents a more "user friendly" way of setting/getting the field values (by field name and not directly by index). So the code above would then look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;updateRows = arcpy.da.UpdateCursor(myTbl, ["MY_FIELD"])
for updateRow in updateRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldValue = updateRow[updateRows.fields.index("MY_FIELD")] 
&amp;nbsp;&amp;nbsp;&amp;nbsp; field value = fieldValue + 10
&amp;nbsp;&amp;nbsp;&amp;nbsp; updateRows.updateRow(updateRow)
del updateRow, updateRows&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope some of this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:07:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124384#M9679</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T07:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124385#M9680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great, l'll give it a try.&amp;nbsp; If someone else out there wants to advocate for the "with" block syntax, I'm curious.&amp;nbsp; In the meantime I'll test this approach.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 18:04:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124385#M9680</guid>
      <dc:creator>HalWatson</dc:creator>
      <dc:date>2013-04-02T18:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124386#M9681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The with statement is bugged currently. I'd avoid it for now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/79647-Clarifying-when-cursor-locks-are-released?p=280350&amp;amp;viewfull=1#post280350"&gt;http://forums.arcgis.com/threads/79647-Clarifying-when-cursor-locks-are-released?p=280350&amp;amp;viewfull=1#post280350&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Apr 2013 18:14:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124386#M9681</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-04-02T18:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Esri python arcpy.da.UpdateCursor - create cursor has failed (script error)</title>
      <link>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124387#M9682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just an "update"&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&amp;nbsp; to close out this thread.&amp;nbsp; The 2nd round of suggested code did not work, so I figured the code approach was probably fine and something else completely was the problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Going in another direction, I decided to register my table with the enterprise geodatabase (SDE 10.1 over PostgreSQL).&amp;nbsp; After doing that, the update cursor works fine.&amp;nbsp; I did not register the table as versioned, so I am making unversioned edits directly to the base table, which is what I wanted in the first place.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What tripped me up was that insert cursors and search cursors did not require that the table be registered with the geodatabase, but it looks like update cursors are different, which is understandable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks very much for your suggestions, which had a lot of good code and hints that I took away and helped move me forward.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hal&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If anyone knows how to mark this thread as solved, feel free.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Apr 2013 14:38:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/esri-python-arcpy-da-updatecursor-create-cursor/m-p/124387#M9682</guid>
      <dc:creator>HalWatson</dc:creator>
      <dc:date>2013-04-03T14:38:50Z</dc:date>
    </item>
  </channel>
</rss>

