0

I decided to completely restructure the code I was using for my ingest/QAQC script that I am building. I managed to get around using a table join for the first QA/QC part, but this part may require the join. Here's my code block.

 def findRevisit(): #Looks for revisited in the incoming data set using table join and DT(date) field. Flags potential revisits with '2' in QAQC_FLAG field.
 arcpy.env.workspace = inPGDB
 rtTbl = "midFCviewJoin_vw"
 leftTbl = in_table_view
 joinField = "UUID"
 dateField = "DT"
 updField = "QAQC_FLAG"
 fields = [joinField,dateField,updField]
 leftDate = in_table + "." + dateField
 rtDate = midFCview+ "." + dateField
 arcpy.AddJoin_management(leftTbl,joinField,rtTbl,joinField)
 ## arcpy.JoinField_management(leftTbl,joinField,rtTbl,joinField,"")
 sql = leftTbl + "." + joinField + " <> " + rtTbl + "." + joinField
 print "SQL where clause: " + sql
 with arcpy.da.UpdateCursor(leftTbl,[dateField,updField],sql) as cursor:
 for rec in cursor:
 rec[1]=2 ##Set QAQC flag = 2 for possible revisits in the incoming dataset
 cursor.updateRow(rec)
 print rec
 ## arcpy.DeleteField_management(in_table, "QAQC_FLAG_1")
 arcpy.RemoveJoin_management(leftTbl)
 return leftTbl,rtTbl,sql
 del cursor,rec

Seems like it should run. Both table views are in the same workspace. It still falls on its face. Here is the error I get from the cursor:

 Traceback (most recent call last):
 File "C:/Users/kgaines/Documents/Aquadat/Scripting/AquaDat_tableCreate_findDup_findRevisit_defFunct.py", line 232, in <module>
main()
 File "C:/Users/kgaines/Documents/Aquadat/Scripting/AquaDat_tableCreate_findDup_findRevisit_defFunct.py", line 225, in main
findRevisit()
 File "C:/Users/kgaines/Documents/Aquadat/Scripting/AquaDat_tableCreate_findDup_findRevisit_defFunct.py", line 169, in findRevisit
for rec in cursor:
 RuntimeError: Too few parameters. Expected 2.

Where is the "Too few parameters" error coming from?

Here are a couple of images showing the field names in the in_table. All of the other tables and views have exactly the same fields.

Screenshot 1

Screenshot 2

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 11, 2017 at 17:51
5
  • Try defining the the fields like this: "fields = [dateField,updField]" or more explicitly if you can as "fields = ['DT', 'QAQC_FLAG'] prior to calling it in UpdateCursor. Commented Jan 11, 2017 at 18:23
  • Still gives the too few parameters error. I don't get it. This should work! Grrrr!!!! Commented Jan 11, 2017 at 18:27
  • Are dateField and updField part of leftTbl? or are they part of rtTbl? If latter as I suspect, the problem is that after joining the tables the joins are not recognized by UpdateCursor, so that's why it is throwing an error saying that it requires two arguments. I think you want to save/export the joined table and then perform UpdateCursor. Commented Jan 11, 2017 at 18:38
  • dateField and updField actually belong to both tables. The tables share a common field design. I am starting to think that the join isn't going to work in this form. I may have to use some other method to pull out the UUIDs of records that meet the search criteria and use those to update the master in_table before creating the XY layer and outFC. Commented Jan 11, 2017 at 20:52
  • I think you need to to include UUID as a field in the UpdateCursor as well and double your SQL syntax as well. I'm including a modified script below. Hopefully that'll help. Commented Jan 11, 2017 at 21:25

1 Answer 1

1
 def findRevisit():
 arcpy.env.workspace = inPGDB
 r_Table = "midFCviewJoin_vw"
 l_Table_view = in_table_view
 arcpy.MakeTableView_management(r_Table, r_Table_view) #assuming that the left table is already 'table view'
 #Joining Tables
 arcpy.AddJoin_management(l_Table_view, "UUID", r_Table_view, "UUID")
 #Create a table view out of joined tables
 arcpy.MakeTableView_management(l_Table_view, joined_table)
 fields = ["UUID", "DT", "QAQC_FLAG"]
 sql = '"UUID" <> "UUID"'
 #Here I assume you are saying: Change DT value to 2 
 with arcpy.da.UpdateCursor(joined_table, fields, sql) as cursor:
 for rec in cursor:
 rec[1] = 2 ##Set QAQC flag = 2 for possible revisits in the incoming dataset
 cursor.updateRow(rec)
 print rec
 arcpy.RemoveJoin_management(joined_table)
 return l_Table_view, r_Table_view, sql
 del cursor, rec
answered Jan 11, 2017 at 21:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.