I am trying to run this code in the Python terminal in ArcGIS, but everytime it throws an error and I can't figure it out. I think it probably has something do with how I construct the SQL where clause because when I remove that it works fine.

import arcpy
import numpy as np

outputFile = "F:\\output\\data.csv"
tableName = "myTable" 
pointsName = "folder\\myPoints"

pointsArr = arcpy.da.FeatureClassToNumPyArray(pointsName, ('id', 'KEY'))
keyStr = ", ".join(map(str, pointsArr['KEY']))
sql = "{0} IN ({1})".format(arcpy.AddFieldDelimiters(tableName, 'key'), keyStr)
tableArr = arcpy.da.TableToNumPyArray(tableName, ('key', 'column'), where_clause=sql)
numpy.savetxt(outputFile, tableArr, delimiter=",", fmt='%s')

This is the error I get when I try to run it in ArcGIS.

Traceback (most recent call last):
  File "<string>", line 12, in <module>
RuntimeError: The database was not found.

Can any help me figure out how to get this working? Basically what I'm attempting to do is get the keys from my 'points' layer and then use those keys to query a standalone table.

  • Have you set the environment workspace?
    – SMiller
    Commented Apr 18, 2020 at 1:41
  • I am runnning it from within the ArcGIS Python terminal, so I believe that is unnecessary. Besides, it runs just fine if you take out the where-clause parameter.
    – mwsmws22
    Commented Apr 18, 2020 at 2:09
  • By "ArcGIS Python terminal" do you mean the Python window of ArcGIS Pro or of ArcMap, or something else?
    – PolyGeo
    Commented Apr 18, 2020 at 2:59
  • The Python window of ArcGIS Pro.
    – mwsmws22
    Commented Apr 18, 2020 at 3:46

1 Answer 1


I figured out my issue. The key field in my data was a string, not an integer. Therefore, the key values need to be in single quotations marks in the SQL string. Here is my fix:

keyStr = "\'" + "\', \'".join(map(str, pointsArr['KEY'])) + "\'"
sql = "key IN ({0})".format(keyStr)

Your Answer

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

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