Hi All,
I've found an issue with using 'TOP N' in the sql_clause parameter and the default * wildcard for fields when executing a arcpy.da.SearchCursor. The resulting error message:
An expected Field was not found or could not be retrieved properly. [TOP 1 OBJECTID]
- ArcGIS 10.6
- Occurs in both ArcCatalog python window and 64-Bit python console (ArcGISx64106\python.exe)
- Database is SQL Server 2017, licensed geodatabase
- Occurs ONLY in registered Feature Classes....
- I have an assortment of versioned, archived and non-versioned/non-archived, in feature dataset, non-feature dataset, all fail with the same error.
- I have 1 registered table in the geodatabase that does NOT fail and a number of other non-registered/non-objectid tables that also do NOT fail.
- I have a few non-registered spatial tables with a generic column call OBJECTID that do NOT fail
- I tried a couple different geodatabases in the same server, all fail same way. I don't have a second database server to test right now.
- The generic SELECT TOP 1 * FROM FC(_evw) works fine in SSMS
- Works fine if I include a specific fields list... but that requires extra code step and performance hit to run "describe"
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"YourDatabaseConnectionFile.sde/Database.Schema.FeatureClass"</SPAN>
sql_clause <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"TOP 1"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> None<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN> sql_clause<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> rows<SPAN class="punctuation token">:</SPAN>
row <SPAN class="operator token">=</SPAN> rows<SPAN class="punctuation token">.</SPAN>next<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> row
Runtime error
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> An expected Field was <SPAN class="operator token">not</SPAN> found <SPAN class="operator token">or</SPAN> could <SPAN class="operator token">not</SPAN> be retrieved properly<SPAN class="punctuation token">.</SPAN> <SPAN class="punctuation token">[</SPAN>TOP <SPAN class="number token">1</SPAN> OBJECTID<SPAN class="punctuation token">]</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks Fred