Hello, I am trying to write some Python scripts to query a REST endpoint but am not very familiar with SQL lingo. I would like to do it in the environment of the ArcGIS REST Services Directory for a particular map service layer. How would I go about finding the minimum value of the Object ID as well as the maximum value of the Object ID in the 'Where' clause? It is probably very simple so sorry for the lack of understanding.
Thanks!
Solved! Go to Solution.
Not sure how to do it with 'Where Clause' but you could return the stats on the layer from the REST Query to get the min and max.
e.g.leave all blank and use this for Output Statistics
[{"statisticType":"min","onStatisticField":"objectid", "outStatisticFieldName":"MinID"},
{"statisticType":"max","onStatisticField":"objectid", "outStatisticFieldName":"MaxID"}]
example using ESRI sample server:
You should be able to do this via a subquery:
id = (select max(id) from table_name)
To do this, standardized queries must be set to true:
About standardized queries—Documentation (10.3 and 10.3.1) | ArcGIS for Server
I can’t figure out how to specify the table_name variable in the suggested subquery:
id = (select max(id) from table_name)
and then also form the appropriate query with the subquery embedded within it. Everything I try, including the value “table_name” itself, gets me a “Cannot open table for Load” error.
Any suggestions?
Table_name can be replaced with the actual name of the table on disk or DBMS. Are you using SDE or a FGDB here?
I'm actually trying to query a MapServer REST endpoint In the ArcGIS REST Services Directory. I set it up as an SDE.
Not sure how to do it with 'Where Clause' but you could return the stats on the layer from the REST Query to get the min and max.
e.g.leave all blank and use this for Output Statistics
[{"statisticType":"min","onStatisticField":"objectid", "outStatisticFieldName":"MinID"},
{"statisticType":"max","onStatisticField":"objectid", "outStatisticFieldName":"MaxID"}]
example using ESRI sample server:
Perfect! Worked like a charm. Thank you! Thank you!
Just wanted to let you know that this was a huge help to me today. Thanks!
I was wondering if anybody is having problems using select(max) in ArcServer 10.5. I have a 10.2 rest service that is querying a layer with this where clause "ElectionDate in (SELECT max(ElectionDate) FROM PollingPlaceHistory)" and it works fine. But the 10.5 service using the same data will not work.