Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to get the make table query running in a script. IF I simply export the script from a model, it works without a problem. However, I do have to change the variable names, as this will be part of a bigger script. As soon as I change any variable names, it won't work anymore. See example:

# Import arcpy module
import arcpy

# set outputs to be overwritten
arcpy.env.overwriteOutput = True

#WORKS
# Local variables:
AA_allDomains = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AA_allDomains"
AB_BusBar_Domains = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AB_BusBar_Domains"

QueryTable1 = "QueryTable1"
# Process: Make Query Table
inList = [AA_allDomains, AB_BusBar_Domains]
##fieldList = "AA_allDomains.Code #;AA_allDomains.Desc #;AA_allDomains.DomainName #;AB_BusBar_Domains.dataset #;AB_BusBar_Domains.featureclass #;AB_BusBar_Domains.field #;AB_BusBar_Domains.domainName #"
fieldList = [["AA_allDomains.Code", 'CODE'],["AB_BusBar_Domains.dataset", 'DATASET']]
expression = "AB_BusBar_Domains.domainName = AA_allDomains.DomainName"
arcpy.MakeQueryTable_management(inList, QueryTable1, "USE_KEY_FIELDS", "", fieldList, expression)

#DOESN'T WORK
# Local variables:
in1 = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AA_allDomains"
in2 = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AB_BusBar_Domains"

QueryTable1 = "QueryTable1"
# Process: Make Query Table
inList = [in1, in2]
##fieldList = "in1.Code #; in1.Desc #; in1.DomainName #; in2.dataset #; in2.featureclass #; in2.field #; in2.domainName #"
fieldList = [["in1.Code", 'CODE'],["in2.dataset", 'DATASET']]
expression = "in2.domainName = in1.DomainName"
arcpy.MakeQueryTable_management(inList, QueryTable1, "USE_KEY_FIELDS", "", "fieldList", expression)

I already tried to play around with different DB types, different ways of accessing the fields,... but nothing worked out so far and I am starting to get a bit desperate here.

Thanks in advance for any suggestions!

Cheers,

David

share|improve this question
    
Can you provide an example of the error you are getting? –  Fezter Jan 16 '13 at 3:19
1  
I was comparing the working part of the code with the part that doesn't work and discovered that your last line has fieldList in quotes. Whereas, the working part, fieldList is not in quotes. Try removing the quotes. –  Fezter Jan 16 '13 at 3:46
    
I think @Fezter is right - you need the variable called fieldList not a "fieldList" string –  PolyGeo Jan 16 '13 at 7:21
    
I also think Fezter is right. the only difference between "works" and "doesn't works" is making the fieldList a string. –  Emi Jan 16 '13 at 11:11
    
ok, that was just a minor mistake left from trying different things earlier. However, the error I get is that it can"t access the fields: ExecuteError: ERROR 999999: Error executing function. An expected Field was not found or could not be retrieved properly. [QueryTable1] An expected Field was not found or could not be retrieved properly. [Code] An expected Field was not found or could not be retrieved properly. [Code] Failed to execute (MakeQueryTable). –  David Jan 16 '13 at 19:54
add comment

1 Answer

up vote 5 down vote accepted

In the code that works you have:

# Local variables:
AA_allDomains = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AA_allDomains"
AB_BusBar_Domains = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AB_BusBar_Domains"

fieldList = [["AA_allDomains.Code", 'CODE'],["AB_BusBar_Domains.dataset", 'DATASET']]
expression = "AB_BusBar_Domains.domainName = AA_allDomains.DomainName"

This works because your field names in fieldList abd expression are prefixed by the feature class name i.e. AA_allDomains.Code. In the example I just gave, you have the feature class (or table) name "." (dot) the field name. It just so happens that the variable in your working script is also given the feature class name.

In your code that doesn't work you have:

# Local variables:
in1 = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AA_allDomains"
in2 = "D:\\Student\\DomainsToTables\\featureDomains.gdb\\AB_BusBar_Domains"

fieldList = [["in1.Code", 'CODE'],["in2.dataset", 'DATASET']]
expression = "in2.domainName = in1.DomainName"

In this case your field names in fieldList and expression are prefixed by the variable name i.e. in1.Code instead of the feature class (or table) name.

I would recommend that you can change the variable names, but don't change any strings (text between quotes)

share|improve this answer
    
Thanks to all for the suggestions @Brian: that's the solution. I got confused by what was exported by the model builder. Thanks a lot! –  David Jan 16 '13 at 20:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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