Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use SelectLayerByAttribute to find the last point added to a FC. I figured I could use the objectid field because it's serial. I wrote the following:

arcpy.SelectLayerByAttribute_management("controller", "NEW_SELECTION", """ "OBJECTID" = (SELECT MAX("OBJECTID") FROM controller) """) 

following the notes on found here

However, I get the following error:

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\", line 6494, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).

I'm using a Postgres geodatabase and I know all the db's require slightly different formatting requirements. This one I can't figure out though.

share|improve this question
up vote 2 down vote accepted

Field names aren't escaped as far as I know in Postgres. Try


as your where clause.

share|improve this answer
.. and use AddFieldDelimiters to compose queries without worrying for the underlying DBMS syntax… – Alex Tereshenkov Nov 9 '13 at 22:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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