Dear Python experts,
Using Python and cx_Oracle, I would like to query an Oracle SDE table (50 columns) and write the resulting data rows into a non-spatial File GDB feature class. Eventually, I will use this feature class and UpdateCursor to update custom fields in a mosaic dataset.
Is there a way I can convert the SQL query directly into a File GDB feature class?
Trying the numpy method (field mapping the 50 columns is going to be fun!) , I converted the query results to a numpy array and then wrote them to a feature class but the date fields get converted to datetime fields. I need dates only and I want to get it right before I proceed further.
Here's the code I have so far:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np
<SPAN class="keyword token">import</SPAN> cx_Oracle
out_tbl <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Temp\work.gdb\img_source_qry'</SPAN>
connstr<SPAN class="operator token">=</SPAN><SPAN class="string token">'username/password@port/service'</SPAN>
con <SPAN class="operator token">=</SPAN> cx_Oracle<SPAN class="punctuation token">.</SPAN>connect<SPAN class="punctuation token">(</SPAN>connstr<SPAN class="punctuation token">)</SPAN>
curs <SPAN class="operator token">=</SPAN> con<SPAN class="punctuation token">.</SPAN>cursor<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
sqlQry <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""
SELECT n_frame, t_available, d_flying
FROM db.table
where ROWNUM < 10
"""</SPAN>
curs<SPAN class="punctuation token">.</SPAN>execute<SPAN class="punctuation token">(</SPAN>sqlQry<SPAN class="punctuation token">)</SPAN>
datArray <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
cxRows <SPAN class="operator token">=</SPAN> curs<SPAN class="punctuation token">.</SPAN>fetchall<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> cxRow <SPAN class="keyword token">in</SPAN> cxRows<SPAN class="punctuation token">:</SPAN>
datArray<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>cxRow<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># delete output feature class if it exists</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN>out_tbl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>out_tbl<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#define array and write fc</SPAN>
numpyarr_out <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN>datArray<SPAN class="punctuation token">,</SPAN> np<SPAN class="punctuation token">.</SPAN>dtype<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Frame'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'<f8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Available'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'S2'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Date_Fly'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'M8[us]'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>NumPyArrayToTable<SPAN class="punctuation token">(</SPAN>numpyarr_out<SPAN class="punctuation token">,</SPAN> out_tbl<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#close the connections</SPAN>
curs<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> cxRows<SPAN class="punctuation token">,</SPAN> curs
<SPAN class="keyword token">print</SPAN> datArray
con<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
This is the output, I am getting

Appreciate your advice. Thanks!