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.?
Solved! Go to Solution.
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}")
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}")