Skip To Content

Table

Summary

Provides access to basic table properties and methods.

Discussion

There are two ways tables can be referenced in a script for use in a project. To reference tables already in a project, use the listTables method on the Map Class. To reference tables directly from a workspace, use the Table function.

You may want to reference a table in a project using the listTables function because you may need to change a table's data source, its definition query, or even remove the table from the project using the removeTable method.

The Table function is useful for referencing new tables you want to add into a project. Once you have a reference to a new, external table source, you can add it to a Map using the addTable method.

Changing a tables's data source is a common requirement. There is a method and a property on the Layer object that help with this. For a more detailed discussion, parameter information, scenarios, and code samples, please refer to the Updating and fixing data sources help topic.

Properties

PropertyExplanationData Type
connectionProperties
(Read Only)

Returns a table's data source connection information as a Python dictionary.

Dictionary
dataSource
(Read Only)

Returns the complete path for the tables's data source. It includes the full workspace path and name of the dataset.

String
definitionQuery
(Read and Write)

Provides the ability to get or set a tables's definition query.

String
isBroken
(Read Only)

Returns True if a table's data source is broken.

Boolean
name
(Read and Write)

Provides the ability to set or get the name of a table the way it would appear in the table of contents. Spaces can be included.

String

Method Overview

MethodExplanation
getSelectionSet ()

Returns a table's selection as a Python set of Object IDs.

setSelectionSet ({oidList}, {method})

Sets a table's selection using a Python list of Object IDs.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate})

Replaces connection properties using a dictionary or a path to a workspace.

Methods

getSelectionSet ()
Return Value
Data TypeExplanation
List

Returns a table's selection as a Python set of Object IDs.

Provides an easy way to retrieve the table's current selection.

setSelectionSet ({oidList}, {method})
ParameterExplanationData Type
oidList
[oidList,...]

A Python list of Object IDs to use along with the appropriate selection method.

(The default value is None)

List
method

A string that specifies which selection method to use.

  • NEWCreates a new record selection from the oidList.
  • DIFFERENCESelects the records that are not in the current selection but are in the oidList.
  • INTERSECTSelects the records that are in the current selection and the oidList.
  • SYMDIFFERENCESelects the records that are in the current selection or the oidList but not both.
  • UNIONSelects all the records in both the current selection and those in the oidList.

(The default value is NEW)

String

This method provides an easy way to manage a table's selection. To clear the selection, use the NEW selection method with an empty list or don't set any parameters. Python lists are used for the oidList, but sets get returned from the getSelectionSet method on the Table object.

updateConnectionProperties (current_connection_info, new_connection_info, {auto_update_joins_and_relates}, {validate})
ParameterExplanationData Type
current_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties to the source you want to update.

String
new_connection_info

A string that represents the workspace path or a Python dictionary that contains connection properties with the new source information.

String
auto_update_joins_and_relates

If set to True, the updateConnectionProperties method will also update the connections for associated joins or relates.

(The default value is True)

Boolean
validate

If set to True, the connection properties will only be updated if the new_connection_info value is a valid connection. If it is not valid, the connection will not be replaced. If set to False, the method will set all connections to match the new_connection_info, regardless of a valid match. In this case, if a match does not exist, then the data sources would be broken.

(The default value is True)

Boolean

For more detailed discussion, parameter information, scenarios, and code samples, refer to the Updating And Fixing Data Sources help topic.

Code sample

Table example 1

The following script will print the stand-alone table names that have a broken data source for all tables in all maps.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
for m in aprx.listMaps():
    for tbl in m.listTableViews():
        if tbl.isBroken:
            print("Table: {0} is broken in map: {1}".format(tbl.name, m.name))
del aprx
Table example 2

The following script will add a table from a file geodatabase into a map.

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
addTab = arcpy.mp.Table(r"C:\Projects\YosemiteNP\Data_Vector\YosemiteData.gdb\NHDFCode")
m = aprx.listMaps("Yose*")[0]
m.addTable(addTab)
del aprx