AnsweredAssumed Answered

SQL syntax for Python API FeatureLayer.calculate

Question asked by mitch.east86_GADNRWRD on Mar 8, 2018
Latest reply on Mar 9, 2018 by bixb0012

I need to update the values of a column in an ArcGIS online feature service with the value of another row. See the table below where Length(ft) (data type short int) is the target column and the Shape__Length column (data type = double) is the source.

Since this will need to be done for thousands of records periodically I want to create a script that does this using the Python API for ArcGIS. It looks like the arcgis.features module has a FeatureLayer.calculate method that should do this.

To test it I ran the lines below which successfully updates the value of the Length (ft) column.

 

From arcgis import GIS, features

mygis = GIS (“arcgis.com”, username, password)

GMitem = mygis.content.get(itemid)     ###where item is a feature layer collection

test = GMitem.layers[9]                        ###get the 10th layer in the feature layer collection (see attribute table above)

print (test.calculate(where= "1=1",calc_expression={"field": "Length", "value": "1"}))

 

However, when I alter the SQL to the below it throws an error saying it can’t convert “Shape__Length” to a small int so I know it’s reading my column name as text.

 

print (test.calculate(where= "1=1",calc_expression={"field": "Length", "value": "Shape__Length"}))

 

What is the correct syntax to get a field to accept the values of another field using SQL expressions in the Python API??

Attachments

Outcomes