I am trying to write a list of items to a new table in Arc. When I attempt to add a new row to an Arc table, I get the following error:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1170, in InsertCursor
    return gp.insertCursor(dataset, spatial_reference)
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 369, in insertCursor
    self._gp.InsertCursor(*gp_fixargs(args, True)))
RuntimeError: 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]

I have narrowed down the error to using arcpy.InsertCursor() on a table created by using the arcpy.CreateTable_management() tool. I have recreated the problem using this code snippet:

tbl = arcpy.CreateTable_management (r'C:\GeoDatabase.gdb',"Table")
arcpy.AddField_management (tbl, "NewField", "FLOAT")
irows = arcpy.InsertCursor (tbl)

I get an error as soon as I try to execute the last line. This seems very simple, so I feel like I must be overlooking something. However, the InsertCursor tool does not use SQL statements, so the error is confusing to me. Can anyone help me understand how to bypass this error. If you know a better way to take a list of items and write them to a new table in Arc, I am all ears.

Thanks for the help.

  • 1
    It depends on your exact requirements but "a better way to take a list of items and write them to a new table" may be to use the Table To Table tool with a Field Map. – PolyGeo Nov 4 '13 at 1:36
  • PolyGeo - thanks for taking the time to address my question. I tested the Table to Table tool and was able to get it to work with a Field Map, but in my case it was easier to just change the input parameter name as suggested by Paul. – DonnRK Nov 4 '13 at 14:09

I also get the same error on Arcmap 10.1 SP1. I scratched my head and after playing around with it, I tried manually (without arcpy) and used a different table name.

Well it's as simple as that: the software dislikes having a table called Table! Very frustrating....

tbl = arcpy.CreateTable_management (r'C:\GeoDatabase.gdb', "Table1") #Note the 1 at the end
arcpy.AddField_management (tbl, "NewField", "FLOAT")
irows = arcpy.InsertCursor (tbl)

This code worked for me within ArcMap as well as a standalone script.

| improve this answer | |
  • Paul - Thanks for the feedback and answer. I'm not certain as to why Arc doesn't like a table named "Table", but changing that parameter name worked perfectly. I ran my code in a python IDLE window and the code was indifferent to the table named "Table", but running the code through the arc toolbox crashed when I named the table "Table". – DonnRK Nov 4 '13 at 14:07
  • I realize this is a bit off topic but I have run into this type of problem with arcpy before, getting different behaviors when running the same script in a python IDE and as a tool. One thing I was told to try was using a model instead of a script, but this may not help in your case. – dblanchett Nov 5 '13 at 14:16

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.