AnsweredAssumed Answered

Problem with CopyRows_management to in memory with Python 3

Question asked by kreuzrsk on Sep 6, 2019
Latest reply on Apr 7, 2020 by Dan_Patterson

One of my users has a script that works in 2.7 and was working with 3.x but now breaks after the ArcGIS Pro 2.4.1 update.  When copying an SDE table into memory using the arcpy.CopyRows_management all text field sizes are increasing from what there are to 5000.  For example, text fields of size 1 and 100 become 5000.  Our tables are a SQL 2012 / SDE 10.4.1 geodatabase.  To see if I could replicate this issue I even created an empty table from scratch containing only two fields, the first is DataSource defined text length 100 and the other is Flag defined as text length 1.

 

Is anyone else seeing this?  The user says it was working in version 3 before we pushed out Pro 2.4.1.

 

c:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3>python.exe h:\treg\test_inmemory2.py
SDE table is : H:\Treg\(Prod) MyDatabase@Reader.sde\MyDatabase.DBO.WS_Test

OBJECTID is a type OID with a length of 4

DataSource is a type String with a length of 100
Flag is a type String with a length of 1

 

Copying table H:\Treg\(Prod) MyDatabase@Reader.sde\MyDatabase.DBO.WS_Test into memory...

 

temp table is : memory\tmpTable

OBJECTID is a type OID with a length of 4
DataSource is a type String with a length of 5000
Flag is a type String with a length of 5000

 

try:
    ##Import modules
    import os, sys
    import os.path as path
    import traceback

    import arcpy
    from arcpy import env

    arcpy.env.overwriteOutput = True

   
    sdeTable = r"H:\Treg\(Prod) MyDatabase@Reader.sde\MyDatabase.DBO.WS_Test"
    tmpTable = r"memory\tmpTable"   

    print('SDE table is : {}\n' .format(sdeTable)) 
   
    ##check field lengths in SDE text fields
    fields = arcpy.ListFields(sdeTable)
    for field in fields:
        print('{0} is a type {1} with a length of {2}'.format(field.name, field.type, field.length))

    print ('\nCopying table {} into memory...'.format(sdeTable))
    arcpy.CopyRows_management(sdeTable, tmpTable)   
   

    print('\ntemp table is : {}\n' .format(tmpTable))   

    ##check field length on in memory text fields
    fields = arcpy.ListFields(tmpTable)
    for field in fields:
        print('{0} is a type {1} with a length of {2}'.format(field.name, field.type, field.length))

except:
    print ('\n*** ERROR IN SCRIPT!')
    print ('\n***PYTHON ERROR INFO: \n' +  str(traceback.format_exc()))

Outcomes