I am trying to convert a psql query string into arcpy formatting for an UpdateCursor where expression parameter:

'''SELECT \"NAME_0\",\"NAME_1\",\"NAME_2\",\"NAME_3\",\"NAME_4\",\"NAME_5\",\"WIKI_URL\", \"LEVEL_DEPT\" FROM 
  • 1
    Select statements in ArcGIS are very basic. ArcGIS is automatically set up to "Select * from [Table]". You only have the ability to add the WHERE clause. You also will not have the ability to use your GROUP BY, HAVING, and ORDER BY statements, Commented Dec 4, 2012 at 19:47
  • okay, thanks I pretty much figured that was the case, but I wanted to make sure because I think the arcpy documentation should have at least made that kind of disclaimer. Commented Dec 4, 2012 at 19:55

1 Answer 1


The UpdateCursor function allows you to filter fields that are returned/updated and allows simple sorting of A-Z/Z-A. I'm assuming you don't want the column/field filters for purely display reasons, but because you only want to update those specific fields?

A rough example:

rows = arcpy.UpdateCursor (r"C:/data/dataset.shp", WIKI_URL > 1,"", [NAME_0,NAME_1,NAME_2,...], WIKI_URL A)

Mind you, that example doesn't have exact syntax, or the full expression you gave above. It will change based on your database backend and needs. If your data is coming from ArcSDE or personal geodatabases, it should support full SQL queries including subqueries. You will have to experiment whether it allows more complex queries in this particular function.

You can use Copy Features to convert data to file, personal, or SDE geodatabases in order to take advantage of enhanced SQL functionality.

You can also use AddFieldDelimiters to take the guesswork out of whether your query should use quotes ("") or brackets ([]) or nothing around fields.

All of the above tools can be accessed through Python scripting.

  • oh, well the data is coming from within arcmap itself. I sort of figured that the sql would be limited and based on the limits of the select by attribute option. Commented Dec 4, 2012 at 22:17
  • yeah I sort of figured the sql would be limited based on the select by attributes option because my data is not from any db, but rather through adding a layer in arcmap. So it doesn't support full queries which I needed. Commented Dec 4, 2012 at 22:20
  • When you say the data comes from ArcMap itself through a layer file, do you mean an intermediate/temporary dataset, or something else? What format is the data in? Python can do a lot, but it is dependent on data format.
    – Baltok
    Commented Dec 4, 2012 at 22:25
  • 1
    In that case, you can convert your shapefile to a personal geodatabase and may be able to use the enhanced SQL abilities to perform your query that way. Then convert the personal geodatabase back to a shapefile after you have updated rows. Just a thought. Anyway, sorry I couldn't help more.
    – Baltok
    Commented Dec 4, 2012 at 22:53
  • 1
    You can use the Copy Features tool to convert your shapefile to a file, personal, or SDE geodatabase and vice versa. The tool can be accessed manually, through Model Builder, or Python.
    – Baltok
    Commented Dec 4, 2012 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.