0

I working on a python script to copy domains from one geodatabase to another (to rebuild replicas/staging environments). I cannot figure out why I get the following error when it the script hits arcpy.da.NumPyArrayToTable(array, table)

Runtime error Traceback (most recent call last): File "", line 70, in File "", line 65, in migrateDomains RuntimeError: An invalid SQL statement was used. [SELECT * FROM table]

Below is my code

inputDomains = arcpy.da.ListDomains(inputDB)                               

tupLst = []

for domain in inputDomains:
    if domain.name == 'gFittingType':
        print('Domain name: {0}'.format(domain.name))
        print(domain.description)
        if domain.domainType == 'CodedValue':                              
            codeValues = domain.codedValues
            for val, desc in codeValues.items():
                tupLst.append((str(val),str(desc)))

        array = np.array(tupLst, dtype=[('code','S50'),('value','S50')])
        table = r'u:\scratch_workspace\scratch.gdb\table'
        arcpy.da.NumPyArrayToTable(array, table)
        arcpy.TableToDomain_management(table,'code','value',targetDB,domain.name,domain.description,'REPLACE')

Additional info (ArcGIS 10.3)

1

I suggest using a GP tool Domain To Table passing in a specific domain gFittingType. You can use an in-memory table to avoid writing to the disk.

temp_table = r"in_memory\data"
arcpy.DomainToTable_management(in_workspace=r"C:\GIS\my.gdb",
                               domain_name="gFittingType",
                               out_table=temp_table,
                               code_field="code", 
                               description_field="value")

Using numpy doesn't make sense when there is already a built-in GP tool created specifically for this.

However, to make my answer complete, the code you've provided doesn't throw any error in my 10.3 environment. This error could be data specific. So unless you are willing to provide more details, it will be hard to troubleshoot.

Some ideas:

  1. Try to run your code with a very simple dummy domain [(0, 'Test1'), (1, 'Test2')] to see if it would work.
  2. Look into your codes and values and whether using S50 makes sense.
  3. Make sure you have permissions to write to the output table. Try testing using a scratch geodatabase: os.path.join(arcpy.env.scratchGDB, 'tableCodes')

Env details:

numpy.__version__
'1.7.1'
  • I ended up going the GPTools route - The idea was to loop through each domain in a production database, and migrate it to an empty database for development testing. We want to automate this because there are ~ 75 domains in our database and manually migrating those has been problematic at best. I will have to do some debugging (mostly out of curiosity/learning desire) to figure out what the issue is with using numpy.array if it worked in your environment. The domains are almost all string data types with matchign coded values/descriptions. – user8378041 Aug 12 '17 at 14:03
0

Ultimately I bypassed the error with GPTools:

arcpy.env.orverWriteOutputs = True

inputDomains = arcpy.da.ListDomains(inputDB)
scratch = r'u:\scratch_workspace\table.dbf'

for domain in inputDomains:
    print('Domain name: {0}'.format(domain.name))
    print('     {0}'.format(domain.description))
    arcpy.DomainToTable_management(inputDB,domain.name,scratch,'code','desc')
    arcpy.TableToDomain_management(scratch,'code','desc',targetDB,domain.name,domain.description,'REPLACE')

elapsedTime(startTime)

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.