4

Is there a way to execute SQL queries on file geodatabase from Python? I'm looking for the same functionality provided by arcpy.ArcSDESQLExecute for SDE databases.

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Jul 12, 2013 at 14:00
1
  • Are you looking to just do a SELECT to the file geodatabase, or a more complex query? Commented Jul 12, 2013 at 17:15

2 Answers 2

4

Most Python queries are limited to a Where clause, however, you can execute a subquery in the Select_By_attribute tool. Please see the ArcGIS SQL Reference for more details. Also, the arcpy.da UpdateCursor and SearchCursor let you issue groupby, distinct, top, order by in a sql_clause along with the where_clause.

From the SQL reference for query expressions used in ArcGIS :

Coverages, shapefiles, and other nongeodatabase file-based data sources do not support subqueries. Subqueries that are performed on versioned ArcSDE feature classes and tables will not return features that are stored in the delta tables. File geodatabases provide the limited support for subqueries explained in this section, while personal and ArcSDE geodatabases provide full support. For information on the full set of subquery capabilities of personal and ArcSDE geodatabases, refer to your DBMS documentation.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Jul 12, 2013 at 22:51
1

It is possible to use arbitrary SQL (though likely with some limitations) with the file geodatabase API driver of GDAL/OGR. See my answer this related question: ogr2ogr / GDAL remove features in FileGDB while in use by ArcGIS Server map service

Also, if you are looking to do this with Python and on Windows take a look at this question: Gdal Python Bindings and File Geodatabase API

answered Jul 13, 2013 at 2:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.