I'm using MakeQueryLayer to create a view from a database table in the ArcMap python window. The command completes successfully but I can't see the result. Where does it go?

arcpy.MakeQueryLayer_management(r'Database Connections\Connection to database.sde',
'csw_test','select * from REPORT_TBL',"OBJECTID (Long Integer, Not nullable)")
<Result 'csw_test'>

Nothing shows up in table of contents, List by Source is active, changing panes and forcing a refresh has no effect. Using AddTableView doesn't work:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\arcgis\desktop10.6\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\arcgis\desktop10.6\arcpy\arcpy\mapping.py", line 113, in AddTableView
    assert isinstance(data_frame, DataFrame)

Python window results

  • 1
    A query table is like a query layer. It's just a rule for data access from Desktop/arcpy. There is no table created, so it doesn't go anywhere. – Vince Nov 5 '18 at 21:45
  • You can persist the View using arcpy.CopyRows_management() to any supported Table format. – klewis Nov 5 '18 at 22:15
  • @klewis ERROR 000732: Input Rows: Dataset csw_test does not exist or is not supported – matt wilkie Nov 8 '18 at 0:26
  • @Vince that doesn't make sense to me. If there is nothing created then there's no need for the tool to exist at all. – matt wilkie Nov 8 '18 at 0:27
  • It's a named query. It exists as an object in the document. It does not exist outside the document. If you want a persistent object, you want to use Create Database View. – Vince Nov 8 '18 at 1:19

This is a bug that's been present since 10.1 - see Bug NIM086004 for status and Geonet 'Can't get reference to result from MakeQueryLayer_management' conversation for actual information. Namely: If query does not return a spatial column the resulting table does not get added to the map document.


(-) Use ArcGIS Pro (v2.1.2+). It just works, the query view shows up as a standalone table without any other action.

(A) Turn off Background Processing and/or:

(B) arcpy.Describe() the result and use that object in future actions:

    input_database="Database Connections/Connection to our_gdb.sde", 

desc = arcpy.Describe(out_layer_name)
t = arcpy.mapping.TableView(desc.name)
arcpy.CopyRows_management(t, "myoutputtable")


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.