<?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 Having trouble with da.InsertCursor. Need help. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/having-trouble-with-da-insertcursor-need-help/m-p/340617#M26727</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm attempting to write a script that will extract specific records from another very large table (29 million records) so that I can run a QC on the extracted data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My plan was to create a set object containing record ID’s I'm interested in. I&amp;nbsp; would then perform a da.SearchCursor to match each of the 29 million records to the values in my set object. Any matching row would then be copied into a new table with a da.InsertCursor instance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It didn’t work and I have no idea why. I only have issues if I try to use a conditional statement to insert rows into a new table. Any other 'then' statement works just fine. Can someone help me figure out where my problem is? Or suggest a work around?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SUMMARY_Set = ([CID, or, a, bunch, of, Community, IDs]) #interested in the ‘CID’ field
FGDB = r'D:\~Working\Developement\RISK\QC_Test.gdb'
BIG_TABLE = r'Database Connections\NC_RISK.sde\NC_RISK.sql.L_DAMAGE_SUMMARY_JURISDICTION'

new_table = os.path.join(FGDB, "L_DAMAGE_SUMMARY_JURISDICTION")
arcpy.CreateTable_management(FGDB, "L_DAMAGE_SUMMARY_JURISDICTION", BIG_TABLE)

FieldNameList = []
fieldnames = arcpy.ListFields(BIG_TABLE)
for field in fieldnames:
&amp;nbsp;&amp;nbsp;&amp;nbsp; FieldNameList.append(field.name)

InsertTable = arcpy.da.InsertCursor(new_table, FieldNameList)
with arcpy.da.SearchCursor(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;BIG_TABLE&lt;/SPAN&gt;, FieldNameList) as searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] in SUMMARY_Set:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InsertTable.insertRow(row)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used the same code without the conditional statement and the rows copied into a new table just fine. it took a while, but all the records were there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(SUMMARY_LAYERS, FieldNameList) as searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InsertTable.insertRow(row)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I modified the code again to only print the matching rows instead of inserting them into a new table. It worked just like I had intended it to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; FieldNameList.index("CID")
0
&amp;gt;&amp;gt;&amp;gt; with arcpy.da.SearchCursor(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;BIG_TABLE&lt;/SPAN&gt;, FieldNameList) as searchRows:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] in SUMMARY_Set:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0] + " is in SUMMARY_Set"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:06:37 GMT</pubDate>
    <dc:creator>JohnLay</dc:creator>
    <dc:date>2021-12-11T16:06:37Z</dc:date>
    <item>
      <title>Having trouble with da.InsertCursor. Need help.</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-with-da-insertcursor-need-help/m-p/340617#M26727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm attempting to write a script that will extract specific records from another very large table (29 million records) so that I can run a QC on the extracted data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My plan was to create a set object containing record ID’s I'm interested in. I&amp;nbsp; would then perform a da.SearchCursor to match each of the 29 million records to the values in my set object. Any matching row would then be copied into a new table with a da.InsertCursor instance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It didn’t work and I have no idea why. I only have issues if I try to use a conditional statement to insert rows into a new table. Any other 'then' statement works just fine. Can someone help me figure out where my problem is? Or suggest a work around?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;SUMMARY_Set = ([CID, or, a, bunch, of, Community, IDs]) #interested in the ‘CID’ field
FGDB = r'D:\~Working\Developement\RISK\QC_Test.gdb'
BIG_TABLE = r'Database Connections\NC_RISK.sde\NC_RISK.sql.L_DAMAGE_SUMMARY_JURISDICTION'

new_table = os.path.join(FGDB, "L_DAMAGE_SUMMARY_JURISDICTION")
arcpy.CreateTable_management(FGDB, "L_DAMAGE_SUMMARY_JURISDICTION", BIG_TABLE)

FieldNameList = []
fieldnames = arcpy.ListFields(BIG_TABLE)
for field in fieldnames:
&amp;nbsp;&amp;nbsp;&amp;nbsp; FieldNameList.append(field.name)

InsertTable = arcpy.da.InsertCursor(new_table, FieldNameList)
with arcpy.da.SearchCursor(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;BIG_TABLE&lt;/SPAN&gt;, FieldNameList) as searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] in SUMMARY_Set:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InsertTable.insertRow(row)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used the same code without the conditional statement and the rows copied into a new table just fine. it took a while, but all the records were there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(SUMMARY_LAYERS, FieldNameList) as searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InsertTable.insertRow(row)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I modified the code again to only print the matching rows instead of inserting them into a new table. It worked just like I had intended it to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; FieldNameList.index("CID")
0
&amp;gt;&amp;gt;&amp;gt; with arcpy.da.SearchCursor(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;BIG_TABLE&lt;/SPAN&gt;, FieldNameList) as searchRows:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] in SUMMARY_Set:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0] + " is in SUMMARY_Set"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set
370042 is in SUMMARY_Set&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:06:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-with-da-insertcursor-need-help/m-p/340617#M26727</guid>
      <dc:creator>JohnLay</dc:creator>
      <dc:date>2021-12-11T16:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with da.InsertCursor. Need help.</title>
      <link>https://community.esri.com/t5/python-questions/having-trouble-with-da-insertcursor-need-help/m-p/340618#M26728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Figured it out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;New code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(BIG_TABLE, FieldNameList) as searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.InsertCursor(&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;new_table&lt;/SPAN&gt;, FieldNameList) as InsertTable:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] in SUMMARY_Set:
&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; InsertTable.insertRow(row)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:06:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/having-trouble-with-da-insertcursor-need-help/m-p/340618#M26728</guid>
      <dc:creator>JohnLay</dc:creator>
      <dc:date>2021-12-11T16:06:39Z</dc:date>
    </item>
  </channel>
</rss>

