Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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\management.py", 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

1 Answer 1

up vote 2 down vote accepted

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

 'OBJECTID = (SELECT MAX(OBJECTID) FROM controller)'

as your where clause.

share|improve this answer
2  
.. and use AddFieldDelimiters to compose queries without worrying for the underlying DBMS syntax resources.arcgis.com/en/help/main/10.2/index.html#//… –  Alex Tereshenkov Nov 9 '13 at 22:23

Your Answer

 
discard

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.