Get FGDB database view's SQL definition using Python

278
1
Jump to solution
05-11-2023 10:28 AM
Bud
by
Notable Contributor

ArcGIS Pro 3.1.1

Is there a way to get a FGDB database view's SQL definition using Python?

For example, I have a file geodatabase database view called TEST_TABLE_VW:

select objectid, case when type = 'NT' then 1 else 0 end as flag from test_table 

Is there a way to assign that SQL text to a Python variable, print it, etc.?

0 Kudos
1 Solution

Accepted Solutions
DannyMcVey
Esri Contributor

The describe object for tables has a "whereClause" property. That should do it.

import arcpy

# Create a table view from a feature class
if arcpy.Exists("view"):
    arcpy.Delete_management("view")
arcpy.management.MakeTableView(
    in_table="a",
    out_view="view",
    where_clause="OID = 0",
)

# Create a Describe object from the table view
desc = arcpy.Describe("view")

# Print some table view properties
print(f"Table View Name: {desc.nameString}")
print(f"Where Clause:    {desc.whereClause}")
print(f"Table Name:      {desc.name}")

 

View solution in original post

1 Reply
DannyMcVey
Esri Contributor

The describe object for tables has a "whereClause" property. That should do it.

import arcpy

# Create a table view from a feature class
if arcpy.Exists("view"):
    arcpy.Delete_management("view")
arcpy.management.MakeTableView(
    in_table="a",
    out_view="view",
    where_clause="OID = 0",
)

# Create a Describe object from the table view
desc = arcpy.Describe("view")

# Print some table view properties
print(f"Table View Name: {desc.nameString}")
print(f"Where Clause:    {desc.whereClause}")
print(f"Table Name:      {desc.name}")