Skip to main 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 or definition query, or even remove the table from the project using the Map class 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.

A table can support zero to many definition queries, but only one definition query can be active. It is also possible that one or many definition queries are present but none are active. There are a couple of ways to manage definition queries. First, you can use the definitionQuery property. If you set a unique SQL string on a table that does not have a definition query or a table that has multiple definition queries, the new definition query is added and it becomes the active query. If you set a SQL string on a table that already has that same query, it sets that as the active definition query, if it is not already active. The second way to manage definition queries is to use the listDefinitionQueries and updateDefinitionQueries functions in combination. The listDefinitionQueries function returns a list of Python dictionaries that represent the properties associated with each query. The dictionary keys are name, sql, and isActive. Definition queries can be added, modified, or removed from the Python list using core Python. The dictionary isActive value can be set to True to set the active query. Again, only one query can be active. If you try setting more than one query to be active, an error will be returned. After changes are made, the updateDefinitionQueries function is used to set the new changes.

The enableTime method allows you to enable time on a table. Once time is enabled, the time property provides access to the LayerTime object allowing you to further configure time properties for a table. Refer to the LayerTime help topic for code samples that also apply to tables.

The fields and rows in a table can be displayed and configured using the TableFrameElement class on a Layout. To create a table frame, use the createTableFrameElement method on the Layout class. See the TableFrameElement class help topic for more information and code examples.

Changing a tables's data source is a common requirement. For a more detailed discussion, parameter information, scenarios, and code samples, refer to the Updating and fixing data sources help topic.

Properties

Name Explanation Data 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 table's data source. It includes the full workspace path and name of the dataset. For enterprise geodatabase tables, a string containing the table's connection information is returned.

Tip:

Enterprise geodatabase tables in an ArcGIS Pro project do not retain the path to the database connection file (.sde) that was used to create the layer.

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

isTimeEnabled

(Read only)

Indicates whether time is enabled on the table. If the isTimeEnabled property returns True, the time property on the table can be used to return a LayerTime object. If time is not enabled, use the enableTime method on a table that contains time information.

Boolean

longName

(Read only)

A table's full name including group layer information if it exists. For example, a table named 'Table' in a group layer named 'Group Layer' will return a longName value of 'Group Layer\\Table'. If the table is not in a group, the longName will be the same as the name value.

String

metadata

(Read and Write)

Get or set the table's Metadata class information.

Note:

Setting metadata is dependent on the isReadOnly property value.

Metadata

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

time

(Read only)

Returns a LayerTime object if time is enabled on the table.

Note:

The LayerTime object has time properties that can be used for both Layer and Table objects.

LayerTime

URI

(Read only)

The Universal Resource Indicator for a table. It is a unique identifier for a table in a project and is sometimes required when using Python CIM access. Once a table is added and the URI is established, the value does not change over time. For example, if you modify the table's name, the URI will not change.

String

Methods

disableTime()

Disables time enabled properties on a Table object.

The enableTime method can be used to re-enable time properties.

enableTime({startTimeField}, {endTimeField}, {autoCalculateTimeRange}, {timeDimension})

Enables time on a table if it has time information.

All parameters on the enableTime method are optional. If startTimeField and endTimeField are not specified, the method will evaluate the data and attempt to come up with appropriate default values.

After running the enableTime method, the time property on the table can be used to return a LayerTime object. If a MapFrame on a Layout contains time-enabled layers or tables, the MapTime class can be used to access map time settings.

Name Explanation Data type

startTimeField

(Optional)

The name of the field containing the start time values. If each row has a single time field, specify that field name in the startTimeField and leave endTimeField blank. If each row has a start and end time field, specify both the startTimeField and endTimeField.

The default value is None.

String

endTimeField

(Optional)

The name of the field containing the end time values. Not all tables use an end time field. If each row has a single time field, specify that field name in the startTimeField and leave endTimeField blank. If each row has a start and end time field, specify both the startTimeField and endTimeField.

The default value is None.

String

autoCalculateTimeRange

(Optional)

If set to True, the start and end time attribute information is used to calculate the table's time extent.

The default value is True.

Boolean

timeDimension

(Optional)

The name of the dimension containing time values when using netCDF data.

The default value is None.

String

getDefinition(cim_version)

Gets a table's CIM definition.

CIM-level access to additional object properties was introduced at ArcGIS Pro 2.4. When you want to return an object's CIM definition, you must specify a cim_version. Esri follows the semantic versioning specification. This means that at major releases—for example, 3.0—breaking API changes are allowed. This allows Python script authors control over which version of the CIM is used during a script run if there is a possibility breaking changes may be introduced in the new version. If you are authoring scripts for ArcGIS Pro 2.x, specify the cim_version to be 'V2'. If you are authoring scripts for ArcGIS Pro 3.x, specify the cim_version to be 'V3'. Scripts authored using cim_version 'V2' will continue to work in ArcGIS Pro 3.x.

For more information about working with the CIM and samples, see Python CIM access.

Name Explanation Data type

cim_version

A string that represents the major version of the CIM.

String

Return value

Data type Explanation

Object

Returns the CIM definition for a Table object.

getSelectionSet()

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

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

Return value

Data type Explanation

List

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

listCharts({wildcard})

Returns a Python list of chart objects in a table.

Name Explanation Data type

wildcard

(Optional)

A wildcard is based on the chart title and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the resulting list.

The default value is None.

String

Return value

Data type Explanation

List

Returns a Python list of chart objects in a table.

listDefinitionQueries({wildcard})

Returns a Python list of definition queries associated with a table.

Definition queries can be added, modified, or removed from the Python list using standard practices. The dictionary isActive value can be set to True to set the active query. Again, only one query can be active. If you try setting more than one query to be active, an error will be returned. After changes are made, the updateDefinitionQueries function is used to set the new changes.

Name Explanation Data type

wildcard

(Optional)

A wildcard is based on the query name and is not case sensitive. A combination of asterisks (*) and characters can be used to limit the resulting list.

The default value is None.

String

Return value

Data type Explanation

List

A Python list of dictionaries that represent the properties associated with each query. The dictionary keys are name, sql, and isActive.

openTableView({show_selected})

Opens and activates a new table view pane in the application.

This is useful if the table view is not already open or different view is active in the application. To close other, existing views before opening a new table view, use the ArcGISProject closeViews method.

Note:

This method is designed to be run in the application using a script tool, Notebook, or the Python window. It will have no effect if run outside of the application.

Name Explanation Data type

show_selected

(Optional)

If set to True, the table view will open displaying only the selected records.

Boolean

pasteProperties(source_table, {table_paste_properties[table_paste_properties,...]})

The pasteProperties method pastes properties from a table to another table.

For more information about pasting table properties, see the Copy and paste properties help topic.

Name Explanation Data type

source_table

A table or feature layer with the properties that will be pasted.

Table

table_paste_properties[table_paste_properties,...]

(Optional)

A single string or a list of strings that specify the property or properties that will be pasted. For example, table_paste_properties="CHARTS" will paste only chart properties, whereas table_paste_properties=["CHARTS", "FIELD_PROPERTIES", "POPUPS"]) will paste multiple properties.

  • ALL—All applicable properties will be pasted.

  • CHARTS—Only chart properties will be pasted.

  • DEFINITION_QUERIES—Only definition query properties will be pasted.

  • DISPLAY_EXPRESSION—Only display expression properties will be pasted.

  • FIELD_PROPERTIES—Only field properties will be pasted.

  • POPUPS—Only pop-up configuration properties will be pasted.

The default value is ALL.

String

saveACopy(file_name)

Saves a table to a layer file (.lyrx).

Both tables and layers can be saved to the layer file (.lyrx).

Name Explanation Data type

file_name

A string that includes the location and name of the output layer file (.lyrx).

String

setDefinition(definition_object)

Sets a table's CIM definition.

For more information about working with the CIM and samples, see Python CIM Access.

Name Explanation Data type

definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

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

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

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.

Name Explanation Data type

oidList[oidList,...]

(Optional)

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

The default value is None.

List

method

(Optional)

A string that specifies which selection method to use.

  • NEW—Creates a new record selection from the oidList.

  • DIFFERENCE—Selects the records that are not in the current selection but are in the oidList.

  • INTERSECT—Selects the records that are in the current selection and the oidList.

  • SYMDIFFERENCE—Selects the records that are in the current selection or the oidList but not both.

  • UNION—Selects all the records in both the current selection and those in the oidList.

The default value is NEW.

String

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

The updateConnectionProperties method replaces connection properties using a dictionary or a path to a workspace.

For more detailed discussion, parameter information, scenarios, and code samples, see Updating and fixing data sources.

Name Explanation Data 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. If an empty string or None is used in current_connection_info, all connection properties will be replaced with the new_workspace_info, depending on the value of the validate parameter.

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

(Optional)

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

The default value is True.

Boolean

validate

(Optional)

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 value, regardless of a valid match. In this case, if a match does not exist, the data sources would be broken.

The default value is True.

Boolean

ignore_case

(Optional)

Determines whether searches will be case sensitive. By default, queries are case sensitive. To perform queries that are not case sensitive, set ignore_case to True.

The default value is False.

Boolean

updateDefinitionQueries(definitionQueries[definitionQueries,...])

Updates a table's collection of definition queries.

This function is typically used to apply the changes that have been made to the results returned by the listDefinitionQueries function.

Name Explanation Data type

definitionQueries[definitionQueries,...]

Updates a list of dictionaries that represent the properties of each definition query for a table.

List

Code sample

Table example 1

The following script prints 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.listTables():
        if tbl.isBroken:
            print(f"Table: {tbl.name} is broken in map: {m.name}")
del aprx
Table example 2

The following script adds 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