<?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: simple insert cursor issues in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565704#M44290</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;TABLE is a terrible test name.&amp;nbsp; Test any other name, just be sure it is not a key word.&amp;nbsp; Test values used by any code should always avoid using keywords when naming objects or fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Feb 2015 17:57:52 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2015-02-11T17:57:52Z</dc:date>
    <item>
      <title>simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565695#M44281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having some weird issues with an insert cursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I have a dictionary, where each key corresponds to a list of orps. I want the inset cursor to iterate over each list in each dictionary key and insert a row with the corresponding values. Seems like it should be simple, but for some reason I keep getting an SQL error. I've used search and update cursors extensively, but haven't had a need for insert cursors before now, so any advice would be very greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the offending code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;match = {}

for o in well_owners:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for p in orps_owners:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if orps_owners
 == well_owners&lt;O&gt;:&lt;/O&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; match&lt;O&gt; = []&lt;/O&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; match&lt;O&gt;.append(p)&lt;/O&gt;

arcpy.CreateTable_management(h, "TABLE")
arcpy.AddField_management("TABLE", "DECWell_", "TEXT")
arcpy.AddField_management("TABLE", "match", "LONG")

for key in match:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.da.InsertCursor("TABLE", ["DECWell_", "match"])
&amp;nbsp;&amp;nbsp;&amp;nbsp; for s in match[key]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow((wellnum[key], s))
&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where well_owners and orps_owners are dictionaries of last names of owners and wellnum is a dictionary of unique identifiers to be written to the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565695#M44281</guid>
      <dc:creator>ThomasCaruso</dc:creator>
      <dc:date>2021-12-12T00:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565696#M44282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It appears you are dealing with a one-to-many relationship of wells to owners and that your match dictionary contains a list of Long values, not a single long value.&amp;nbsp; You must iterate not only over the objects in the match dictionary, but the listed items in the values of that dictionary to insert just the long value, not a list of long values.&amp;nbsp; Additionally, you are not getting the one-to-many relationship preserved in the match dictionary, because you are resetting the list each time you find the same owner name.&amp;nbsp; You should have the logic be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; o &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; well_owners:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; p &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; orps_owners:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; orps_owners&lt;/SPAN&gt;&lt;/SPAN&gt;
 == well_owners&lt;O&gt;:&lt;/O&gt;
&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not o in match:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&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; match&lt;O&gt; = []&amp;nbsp; &lt;/O&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; match&lt;O&gt;.append(p)&lt;/O&gt;&lt;/SPAN&gt;

&lt;OL class="dp-py" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;arcpy.CreateTable_management(h, &lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"TABLE"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;)&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;arcpy.AddField_management(&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"TABLE"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"DECWell_"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"TEXT"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;)&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;arcpy.AddField_management(&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"TABLE"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"match"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"LONG"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;)&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; key &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; match:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.da.InsertCursor(&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"TABLE"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, [&lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"DECWell_"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"match"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;])&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; s &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; match[key]:&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in wellnum[key]:&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="line-height: 12pt; color: black; font-style: inherit; font-size: 9pt; background-color: inherit; font-weight: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow((wellnum[key], item))&amp;nbsp; &lt;/SPAN&gt;
&lt;OL class="dp-py" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;del&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; rows&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could add a check to see if s == [] and still create the wellnum[key] entry with a null item value, assuming you want all matched and unmatched well owners in the final output.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565696#M44282</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-12T00:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565697#M44283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahhh, dammit, that's why I was only getting one match for each well, I figured it was an issue with my lists. Many thanks for your input!! However, when I run the script with the logic you suggested, it gave the error that the "INT object not iterable". I think that this part:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;OL class="dp-py" start="1"&gt;&lt;LI&gt;&lt;SPAN class="keyword"&gt;for s &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; match[key]:&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword"&gt;for item &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; s:&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow((wellnum[key], item))&amp;nbsp; &lt;/LI&gt;&lt;/OL&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it's already understanding "match[key]" as a list object, and "s" as an integer in that list. However, when I took that out and let it run like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for s in match[key]:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow((wellnum[key], s))&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; del rows&lt;/PRE&gt;&lt;P&gt;it's giving me an SQL error of...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"RuntimeError: An invalid SQL statement was used. [SELECT * FROM TABLE]"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in line 71, which, in my script, is this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rows.insertRow((wellnum[key], s))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea what might cause this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565697#M44283</guid>
      <dc:creator>ThomasCaruso</dc:creator>
      <dc:date>2021-12-12T00:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565698#M44284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree I was mistaken about the long value vs. list value in your last loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your DECwell field length should be explicitly set when you create that field to be at least as long as the length of the longest owner name in your list.&amp;nbsp; You just accepted the default text length, which I believe is 50.&amp;nbsp; The moment you try to insert a record with an owner name with 51 characters or more you will get an error.&amp;nbsp; You should add logic to get the longest string length of wellnum[key] in your first loop before creating the field and making sure the new field is long enough (add a little more unless you know the max. field length and it will not grow).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the code you posted never defines the wellnum dictionary, so I cannot be sure that dictionary does not have an issue.&amp;nbsp; If wellnum is an undefined variable then the insertrow line is the first to use it and will throw all sorts of weird errors.&amp;nbsp; If wellnum was defined in code you did not post, are you sure wellnum even has the same key list as the match dictionary?&amp;nbsp; If it might not you need logic to deal with that.&amp;nbsp; i.e., insert a row only when - if key in wellnum:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would say this post is not about simple insert cursor issues, it is about complex dictionary interactions and value evaluation issues.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 16:24:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565698#M44284</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-02-11T16:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565699#M44285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Richard,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just want to thank you again for taking the time to help me out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The DECWell field stores a unique identifier, this identifier is always two letters followed by four numbers, like so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AL1905, RS3000, CH0560&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table being created will only hold that identifier and the objectID of an orps point, so that the well data can be related to matching orps through this table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached is my full code. Note that the feature layers were created because I was interested in selecting orps within a certain distance of the wells and only checking those, as opposed to the entire set of orps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
arcpy.env.overwriteOutput = 1


## define all user inputs for creation of arcmap toolbox

a = arcpy.GetParameterAsText(0) ## wells
b = arcpy.GetParameterAsText(1) ## orps
g = arcpy.GetParameterAsText(2) ## output table
c = arcpy.GetParameterAsText(3) ## well owner name field
d = arcpy.GetParameterAsText(4) ## orps owner name field
h = arcpy.GetParameterAsText(5) ## workspace
e = "OBJECTID"&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;&amp;nbsp;&amp;nbsp; ## objectid of both well and orps data
f = "DECWell_"&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;&amp;nbsp;&amp;nbsp; ## dec well identifier

env.workspace = h

##################### BEGINNING OF MATCH #########################################
## Make feature layers
arcpy.MakeFeatureLayer_management(a, "wells")
arcpy.MakeFeatureLayer_management(b, "orps")
wellsFL = "wells"
orpsFL = "orps"


## Create dictionary of well owners
well_owners = {}
wellnum = {}

## cursor to look through well data, getting DEC well number, owner name and object ID of well.
rows = arcpy.da.SearchCursor(wellsFL, [e, c, f])&amp;nbsp; 
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## split the owner's name in FIRST LAST format at a space, creating a list
&amp;nbsp;&amp;nbsp;&amp;nbsp; owner = row[1].split(" ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## take the last entry in the list and make that the entry for well_owners[objectID]
&amp;nbsp;&amp;nbsp;&amp;nbsp; well_owners[row[0]] = "{}".format(owner.pop().upper())
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## take the well identifier and make that the entry for wellnum[objectid] 
&amp;nbsp;&amp;nbsp;&amp;nbsp; wellnum[row[0]] = str(row[2])&amp;nbsp; 
del rows

## create dictionary of orps owners
orps_owners = {}
## cursor to look through orps data and return name of owner and objectID
rows = arcpy.da.SearchCursor(orpsFL, [e, d])
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## split owner's name in LAST FIRST format at the space, creating a list
&amp;nbsp;&amp;nbsp;&amp;nbsp; owner = row[1].split(" ")
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## take the first item in this list and make that the entry for orps_owners[objectid]
&amp;nbsp;&amp;nbsp;&amp;nbsp; orps_owners[row[0]] = "{}".format(owner.pop(0).upper()) 
del rows

## create dictionary of matches
match = {}
## search through owner's names to find matching names
for o in well_owners:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for p in orps_owners:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if orps_owners
 == well_owners&lt;O&gt;:&amp;nbsp; &lt;/O&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not o in match:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; match&lt;O&gt; = []&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/O&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; match&lt;O&gt;.append(p)&amp;nbsp; &lt;/O&gt;

## create an empty table to fill with matches
arcpy.CreateTable_management(h, "TABLE")
## add relevant fields to the new table
arcpy.AddField_management("TABLE", "DECWell_", "TEXT")&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.AddField_management("TABLE", "match", "LONG")

## create insert cursor to insert a new row in the newly created table for each match found
rows = arcpy.da.InsertCursor("TABLE", ["DECWell_", "match"])
## for each entry in the dictionary of matches
for key in match:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## assign a variable for the unique ID of the well in the first for loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; ID = wellnum[key]
&amp;nbsp;&amp;nbsp;&amp;nbsp; ## iterate through each value in the list of matches
&amp;nbsp;&amp;nbsp;&amp;nbsp; for s in match[key]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## assign a tuple of the values the cursor will insert into the fields of each row
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert = (ID, s)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ## insert new row
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow(insert)&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del rows&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have used an old variation of this script to produce a similar result in the past, and have observed no errors with regards to matching the correct well to the correct orps and getting the right well identifier out of the dictionary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the ArcGIS help for insert cursors, it says that you can select all fields in the table using a " * " in the "field_name" parameter of the cursor, and I thought that perhaps it was messing up because I was using all fields by name instead of using the " * ". So I had the script add a third field and try to use only those two, and also attempted to use the " * " with only two fields, and both still returned the same error that I mentioned above, of incorrect SQL syntax.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565699#M44285</guid>
      <dc:creator>ThomasCaruso</dc:creator>
      <dc:date>2021-12-12T00:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565700#M44286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So just to be clear, the orp field and DECWell contain this 6 character string.&amp;nbsp; In other words, the fields identified by input d (orpNames) and input f (DECwell) hold the same set of values.&amp;nbsp; (again this code is not commented with a lot of meaningless variable names and is complex to follow).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At this point I would add print outputs to verify what the actual ID and s values are within the loop that inserts records immediately prior to inserting each record.&amp;nbsp; Or else put that loop in a try except block and print those values in the except block if you are getting some records inserted and a specific records is failing.&amp;nbsp; Do you know if the failure is always occurring with the first insert record operation, or is it only for a specific record?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 17:30:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565700#M44286</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-02-11T17:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565701#M44287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, I'm really quite new to programming and am entirely self taught. I'll add some explanations to the reply above, however the DEC field holds that identifier, and the "match" field will hold an object ID of an orps point, which will be no higher than 5-6 digits.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 17:41:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565701#M44287</guid>
      <dc:creator>ThomasCaruso</dc:creator>
      <dc:date>2015-02-11T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565702#M44288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would also not ever create a table named TABLE.&amp;nbsp; That is too likely to be a key word somewhere in ArcGIS and you need to avoid naming objects like Tables and fields with key word names.&amp;nbsp; They can bite you in random ways, depending on how the object name is parsed and passed around in the internal code of the tools you are using.&amp;nbsp; Some parts of the code may recognize the value passed as a string for an object name, while other parts may think they are being passed a key word used by SQL in table creation operations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 17:51:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565702#M44288</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-02-11T17:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565703#M44289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"TABLE" was simply my test name so I did not spend all of my time sorting out the parameters of my toolbox instead of trying to debug the script. when it's complete, the name of the table will be assigned by the user when the tool is run. Also, please note that I have updated my full code above with comments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 17:56:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565703#M44289</guid>
      <dc:creator>ThomasCaruso</dc:creator>
      <dc:date>2015-02-11T17:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565704#M44290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;TABLE is a terrible test name.&amp;nbsp; Test any other name, just be sure it is not a key word.&amp;nbsp; Test values used by any code should always avoid using keywords when naming objects or fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 17:57:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565704#M44290</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-02-11T17:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565705#M44291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, that was my mistake it seems. It worked perfectly with another test name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your patience, it's really very appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 18:04:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565705#M44291</guid>
      <dc:creator>ThomasCaruso</dc:creator>
      <dc:date>2015-02-11T18:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565706#M44292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May I suggest that you carefully check the results of your script? You only check on part of the name and when that part of the name already exists in the dictionary the value will be overwritten.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 18:21:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565706#M44292</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-02-11T18:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565707#M44293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;... and BTW, you could find matching owner names using sets:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14236793809541819" jivemacro_uid="_14236793809541819"&gt;&lt;P&gt;lst_matched_owners = list(set(dct_well_owners.values()) &amp;amp; set(dct_orps_owners.value()))&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;More tips can be found here: &lt;A href="https://community.esri.com/docs/DOC-1927"&gt;Some Python Snippets&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 18:30:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565707#M44293</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-02-11T18:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565708#M44294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with Xander that the full code you posted populates dictionaries with the same flaw as I pointed out in the case of the match dictionary.&amp;nbsp; All values in all dictionaries need to be lists, and the list should only be initialized when the key is not in your dictionaries.&amp;nbsp; Then append values to the list each time the dictionary key reappears.&amp;nbsp; Use my suggestion for how to build the match dictionary as an example for the other dictionaries.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 19:13:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565708#M44294</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2015-02-11T19:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565709#M44295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.5pt; font-family: Helvetica, sans-serif;"&gt;While we're at it... although you commented your code, it would be good to use variable names that mean something. Using &lt;EM&gt;a&lt;/EM&gt; till &lt;EM&gt;h&lt;/EM&gt; for the input parameters and settings will make it more difficult to understand the code. It is more understandable to do something like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;## define all user inputs
fc_wells = arcpy.GetParameterAsText(0)
fc_orps = arcpy.GetParameterAsText(1)
tbl_out = arcpy.GetParameterAsText(2)
fld_well_owner = arcpy.GetParameterAsText(3)
fld_orps_owner = arcpy.GetParameterAsText(4)
ws = arcpy.GetParameterAsText(5)
fld_oid = "OID@"
fld_DecWell = "DECWell_"
fld_match = "match"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565709#M44295</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T00:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: simple insert cursor issues</title>
      <link>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565710#M44296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great point Richard. I did a little research and I found the &lt;A href="https://hg.python.org/cpython/file/2.7/Lib/keyword.py"&gt;reserved keywords&lt;/A&gt; in &lt;A href="https://docs.python.org/2/library/keyword.html"&gt;Python 2.7&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;Although &lt;SPAN style="font-family: 'courier new', courier;"&gt;TABLE&lt;/SPAN&gt; is not a Python reserved keyword, it is in &lt;A href="https://technet.microsoft.com/en-us/library/aa238507(v=sql.80).aspx"&gt;SQL&lt;/A&gt; and so it should be avoided.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2015 22:17:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-insert-cursor-issues/m-p/565710#M44296</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-02-11T22:17:54Z</dc:date>
    </item>
  </channel>
</rss>

