ArcGIS 10.1. When I try to export a table view with CopyRows_management, I get an invalid sql error. However, the sql statement by all accounts work fine. When I perform a GetCount_management, the results are correct. Is this a bug?

Code and error:

>>> sql = """"PARCEL_ID" IS NULL"""
>>> outTab = r"C:\Users\e1b8\Desktop\E1B8\Snapping\workspace\workspace.gdb\table"
>>> tab = r"C:\Users\e1b8\Desktop\E1B8\Snapping\Address_Tables_duplicate_addresses.gdb\_Geocode_Failures"
>>> arcpy.MakeTableView_management (tab, "tabView", sql)
<Result 'tabView'>
>>> arcpy.GetCount_management (tab).getOutput (0)
>>> arcpy.GetCount_management ("tabView").getOutput (0)
>>> arcpy.CopyRows_management ("tabView", outTab)
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 13547, in CopyRows
raise e ExecuteError: ERROR 999999: Error executing function. 
An invalid SQL statement was used. 
An invalid SQL statement was used. 
[table] An invalid SQL statement was used. 
[SELECT * FROM table] The table was not found. [table] Failed to execute (CopyRows).  
  • 2
    I'm suspicious of a table name that starts with an underscore - if you drop that does it start working as expected?
    – PolyGeo
    Mar 17 '16 at 21:01
  • Same result I'm afraid, with a table starting with a letter. Mar 17 '16 at 21:04
  • @PolyGeo is right. The problem isn't the view, it's the output target. FGDB tables must conform to SQL naming rules -- initial-alpha extra alphanumeric-or-underscore
    – Vince
    Mar 17 '16 at 21:05
  • 3
    "table" is probably a reserved word, as well.
    – Vince
    Mar 17 '16 at 21:08
  • 1
    I think a self-answer on this will be worthwhile - any causes of 999999 errors that have been tracked to resolution are worth documenting for future searches.
    – PolyGeo
    Mar 17 '16 at 21:22

As stated by @Vince in comments, "table" is a reserved word. After renaming the output table to "tableOutput" the script worked.

>>> outTab = r"C:\Users\e1b8\Desktop\E1B8\Snapping\workspace\workspace.gdb\table"

changed to:

>>> outTab = r"C:\Users\e1b8\Desktop\E1B8\Snapping\workspace\workspace.gdb\tableOutput"
  • 1
    Emil, there are a few more naughty words that should be avoided; have a browse of my answer gis.stackexchange.com/questions/123736/… where I wrote some code trying letter combinations and testing failures - it was tedious but interesting. Mar 17 '16 at 21:55
  • @MichaelMiles-Stimson the script you've mentioned is good. Using itertools permutations would make it much easier to write and read
    – FelixIP
    Mar 17 '16 at 22:16

what is the purpose of copying new rows? to a make a new table? if you are just trying to make a table with an SQL QRY just use the

arcpy.TableSelect_analysis(input, output, sql)
  • This is just experimentation. Mar 17 '16 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.