Select to view content in your preferred language

sql_clause with UpdateCursor does not honor DISTINCT like SearchCursor does

390
0
12-07-2023 01:57 AM
Clubdebambos
Frequent Contributor

Using ArcGIS Pro 3.2

Here is the SearchCursor with sql_clause 

 

with arcpy.da.SearchCursor('Buildings', "type", sql_clause=("DISTINCT type", None)) as cursor:
    for row in cursor:
        print(row[0])
office
church
retail
residential
commercial
public

 

 

and the UpdateCursor with sql_clause

 

with arcpy.da.UpdateCursor('Buildings', "type", sql_clause=("DISTINCT type", None)) as cursor:
    for row in cursor:
        print(row[0])

church
commercial
residential
commercial
commercial
commercial
commercial
retail
church
commercial
retail
commercial
retail
...

 

 

UpdateCursor does not honor the DISTINCT sql_clause like the SearchCursor does. Why?

There is an example in the Esri docs

 

with arcpy.da.UpdateCursor(
        in_features, 
        ["OID@", "STREET_NAME"], 
        sql_clause=("DISTINCT STREET_NAME", None)
) as cur:

 

 

~ learn.finaldraftmapping.com
0 Kudos
0 Replies