I was trying to manually merge file geodatabase tables and was getting Null values for the output file rows and decided to write a python script to merge the files. Here's my script: import arcpy

from arcpy import env
env.workspace = "G:/US county_Climate Hazard models/NWS_County/SUMCounty_NWS_new_frq.gdb"
arcpy.env.overwriteOutput = True
tableList = arcpy.ListTables()
arcpy.Merge_management(tableList, "C:/Documents/ArcGIS/Default.gdb/Merge_sum_freq")

The code takes some time to run but runs without errors. However, when I open ArcMap back again and check for the output, I get duplicate entries in the table I made. Here's how the output looks like:

enter image description here

As you see every entry is duplicated. Could someone explain why is that the case and how could I fix it? Is there something going on with the way I wrote the code?

****EDIT # 1****** I also added:

print tableList

and I got:

[u'CT_09001', u'CT_09003', u'CT_09005', u'Merge_sum_freq']

(I'm not sure why I get this "u" thing)

****EDIT #2***** The original question is now resolved thanks to Michael Miles-Stimson. I accidentally created Merge_sum_freq inside of SUMCounty_NWS_new_frq.gdb

****EDIT #3 NEW Question ***** I have a performance related question: every geodatabase table I need to merge has 1 row and 6 fields (including OBJECTID), which you could see on the screenshot I posted. When I run the above script for 10 tables, it runs in 10sec. For 30 tables - 8sec, 264 tables - ~2min. In the end I need to merge >3000 tables (every table with 1 row, so final table will have >3000 rows). Not sure if I'm extrapolating this right, but it seems like they would complete in >20min. Is this considered a good performance? If not, is there any way I could optimize anything?

  • Hi, welcome to GIS.SE. What's the contents of the original tables? Are there two tables with the same values? Jun 13, 2014 at 1:56
  • @MichaelMiles-Stimson Thank you! originally there were 3 tables, each having one row only. So after merging there should have been just 3 rows with CT_09001, CT_09003, CT_09005. Instead, I got 6 rows.
    – atoregozh
    Jun 13, 2014 at 2:01
  • Try printing your tableList variable to see if it had the value you expect, and edit that result into your Question.
    – PolyGeo
    Jun 13, 2014 at 2:11
  • I think you should reward @MichaelMiles-Stimson by upvoting his Answer, rather than just Accept-ing it, then research/ask your performance/optimization question, separately.
    – PolyGeo
    Jun 13, 2014 at 2:41
  • @PolyGeo I really tried, but unfortunately I don't have enough reputation to do that. I need at least 15 and I have just 8.
    – atoregozh
    Jun 13, 2014 at 2:43

1 Answer 1


Try this:

import arcpy
from arcpy import env

# two traps here for beginners, well spotted!
env.workspace = "G:/US county_Climate Hazard models/NWS_County/SUMCounty_NWS_new_frq.gdb"
env.overwriteOutput = True

outTable = "C:/Documents/ArcGIS/Default.gdb/Merge_sum_freq"

# Clear the way, just to be sure
if arcpy.Exists(outTable):
        import sys
        arcpy.AddError("Unable to delete table, may be locked!")
        sys.exit(-1) # exit here, unable to complete

inTables = arcpy.ListTables()

# report the tables, check here for duplicates
for Tbl in inTables:
    arcpy.AddMessage("Table : " + Tbl)


Have a look at your messages; I have used AddMessage and AddError as I don't know if you're using the toolbox or command line environment, these reporting tools work with both. If you see the table names more than once each there's a problem with listtables (unlikely)... most likely the script was unable to remove the previous table and has appended instead.

  • Thanks! I did everything you said and the messages I got: Table : CT_09001 Table : CT_09003 Table : CT_09005 Table : Merge_sum_freq However, I still get the same output as before ;(
    – atoregozh
    Jun 13, 2014 at 2:18
  • Is there a Merge_sum_freq table in your NWS_County/SUMCounty_NWS_new_frq.gdb database? Jun 13, 2014 at 2:22
  • ahhh thanks, there was, apparently when I was playing around with code I accidentally created one inside!
    – atoregozh
    Jun 13, 2014 at 2:28
  • That explains it! Jun 13, 2014 at 2:59

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.