I have a script that uses the arcpy.MakeQueryTable_management command to join a spatial with a non-spatial table.
It works fine until I add lots and lots more fields into the variable that lists all the fields I want to include. Once it exceeds 255 characters in length, it error's......Understandably as a string can only hold so much.
ie: In the command arcpy.MakeQueryTable_management(tableList, lyrName,"ADD_VIRTUAL_KEY_FIELD", keyField, fieldList, whereClause)
The fieldList variable contains the many fields.
Works when fieldlist looks like this
fieldList = ['Cadastre_Joiner.shape', 'paetbl_CoolingTowers.ApplicationNo', 'paetbl_CoolingTowers.PropAddress']
but breaks when I add lots more field names to this variable exceeding 255 characters.
Does anyone know a better way I can make this work using different processes or methods to enter the field name values ?
Solved! Go to Solution.
What exactly is your error message? I agree with Dan Patterson that the "exceeding 255 characters" error seems odd in this situation.
Are you using an enterprise database? If so, have you thought about using a Query Layer instead?
The Make Query Table documentation is, interesting let's say. The syntax table for the tool shows the in_field parameter with a list format, but the Data Type is listed as Value Table. The example provided reinforces the notion of using a list, but I believe the Data Type part is more accurate in that a Value Table is what is likely being processed by the tool. The tool seems to accept a Python list and converts it into a Value Table, but there appears to be limits to that convenience.
Instead of creating a really long list, I would try creating and populating a Value Table and then pass that into the tool.
Not sure I follow, but if you have a list of fields (ie using ListFields) you can use a list comprehension and a join to produce the lists. Also...that string length limit is not correct. Where did you get that number? The length of a string field in a shapefile?
>>> len(fld_list) # a list of fields...I am using numbers as an example 300 >>> str = ", ".join([str(i) for i in fld_list]) >>> >>> str '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, ........ big snip 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299' >>> >>> len(str) 1388 >>>
What exactly is your error message? I agree with Dan Patterson that the "exceeding 255 characters" error seems odd in this situation.
Are you using an enterprise database? If so, have you thought about using a Query Layer instead?
The Make Query Table documentation is, interesting let's say. The syntax table for the tool shows the in_field parameter with a list format, but the Data Type is listed as Value Table. The example provided reinforces the notion of using a list, but I believe the Data Type part is more accurate in that a Value Table is what is likely being processed by the tool. The tool seems to accept a Python list and converts it into a Value Table, but there appears to be limits to that convenience.
Instead of creating a really long list, I would try creating and populating a Value Table and then pass that into the tool.
Also, check to make sure you do not have a missing quote or comma, and make sure the quotes are of the same type.... a ' for a ' ... and " for a " ... etc. It may be you missed one what using the longer list.
I have had variables longer than 255 character with no issues.
OK now.
It works when I add all the values as a list. I mustn't have formatted it correctly before and it was being interpreted as a very long simple string.
I chose not to use a QueryTable command as it processes the join on the fly every time you use it. I would rather create a feature class from the join. I do this with a CopyFeatures_management command.
It would be great to rename the fields though. It allows Aliases to be defined in this command but I'd prefer to rename the fields. eg. The source field pae_cooling_towers.PrimaryCategory becomes one very long field name "pae_cooling_towers_PrimaryCategory"
Ah yes. I found the AlterField_management command. I will use this to loop through all fields in my temporary featurelayer and remove the originating table name from the front of each field.
http://resources.arcgis.com/EN/HELP/MAIN/10.2/index.html#//001700000198000000