Setting OID Fields in Make Query Layer Function

6609
12
06-02-2016 04:31 PM
MikeMacRae
Occasional Contributor III

Hey all, I am trying to use the:

MakeQueryLayer_management

funtion using arcpy in ArcGIS 10.3.

Make Query Layer—Data Management toolbox | ArcGIS for Desktop

I am trying to set 2 fields as the OID fields (parameter #4). For the life of me, I can't get them to set in the resulting Query Layer. It will set the first one field, but not the second one. I am running this from both a python addin and from the built in python command line window in ArcMap:

arcpy.MakeQueryLayer_management (r"Database Connections\XXXX.sde", "Table_Test3", "select a.tenure_number_id, b.event_number_id from mta_acquired_tenure_svw a, mta_event c, mta_tenure_event_xref b where a.tenure_number_id = b.tenure_number_id and b.event_number_id = c.event_number_id", "TENURE_NUMBER_ID (Long Integer, Not nullable);EVENT_NUMBER_ID (Long Integer, Not nullable)")

The fields are valid. If I were to create a Query layer via the GUI in ArcMap (i.e. File-->Add Data-->Add Query Layer...), the query layer successfully populates and both the OID fields are set because I can manually check off each layer in the second page of the dialogue box. I tried reversing the fields in the query (shot in the dark) and what I've noticed is, it will set the first field in the table as the OID, but not the second. I've tried using the table aliases in the field names. No luck. Any suggestions? thanks.

Tags (1)
12 Replies
RyanMonk1
New Contributor III

Thank you for the update

This bug is currently causing me trouble in ArcGIS 10.2 and Oracle 11g, I'm trying to get a python script automate the exporting of records from dynamically generated query layers.  I can't seem to get it to function exactly the same as the manual process of doing 'File / Add Data / Add Query Layer' then right click 'Export' .

For now I just add an Oracle ROWNUM as the first column in the query to generate an OID.  To make it work I needed to cast it to a Number(10) otherwise ArcGIS thinks it is a Double and won't use it.  "select cast(rownum as number(10)) as objectid, * from ..."

MattWilkie3
Occasional Contributor II

Thank you for the rownum work-around Ryan. I've added it to the conversation at arcgis desktop - Converting double field to integer in database view so ArcMap query layer can use f... 

0 Kudos
PhilLarkin1
Occasional Contributor III
0 Kudos