I want to fetch/extract data from ArcGIS attribute tables (to set some temporal series) using Python. Because of the structure of my tables and their disposition, I thought of using the "division"

Select ... from... Where Not Exists ( Select... From... Where... And...) Group By...

I have then to declare or to set cursors for at least two tables and to add the adequate command lines in my script. I tried this (it doesn't work, I just tried it naively):

import arcpy
rows_n = arcpy.InsertCursor("ndvi_date")
rows_d = arcpy.InsertCursor("Date")
rows_ep = arcpy.InsertCursor("Maroc_Aqua_NDVI_2005_10_decade1_maxPr"
rows_n = rows.newRow()
rows_n.setValue("Date", "Datetime")
rows_n.setValue("NDVI", "Mean")
From nd = rows_n, rows_ep:

 Select "Mean"

 Where Not Exists:

     Select "Datetime" 
     from rows_d
     Where Not Exists:
         Select "Datetime"
         from n2 = rows_n
         Where nd.mean = nd2.mean
         And nd2.Datetime = rows_d.Datetime
Group By id_Province

Bellow is the structure of my tables: enter image description here

enter image description here

So to sum up, what I want is to extract data from my tables, to use the information in my future scripts

  • 1
    "Old-style" cursors are not to be used for new development. They are slow and klunky to operate. I hope you aren't using ArcGIS 10.1, which has been retired for 17 months. You've tagged this with "database", but haven't specified which one. – Vince May 27 at 15:15
  • It's an intern database of arcgis, so it's a geo database. I will edit it and correct it then . – Nour May 27 at 17:26
  • For the cursors, that's how I implemented one of my tables from scratch. That was the only commands that worked – Nour May 27 at 17:29
  • When you ran the code that you have presented what was the full error including line number? – PolyGeo May 27 at 20:09
  • I cannot run it now, my ndvi_date table have problems also. I asked for help for this table in another question ^^" – Nour May 27 at 21:14

It looks like you are mixing languages in your script snippet. The first part is written in Python, but then starting at From nd=... you seem to be switching to SQL.

If you are dealing with a File Geodatabse (.gdb), you will not be able to use straight SQL to manipulate the data - this can only be done on some circumstances in SDE database, which are hosted by a standard RDBMS.

You will need to adopt your code to be fully in Python. As already mentioned in the comments, you are also using the 'old style' cursors. Please take a look at ESRI's documentation for the data access module, specifically the arcpy.da.InsertCursor and arcpy.da.SearchCursor, as it appears you will need to use both here. ESRI's documentation on these is quite good and has some good usage examples. It is recommended to make use of the context manager syntax for these cursors if possible.

  • I figured out that I cannot access the ( .gdb). I mean, I cannot access it with the files name I have on Arcmap, they are registered and named differently. I want to switch its contents to a .mdb but it switches only the shapefiles ( without the stand alone tables, knowing that they the access to them is crucial for my program) – Nour May 28 at 14:13
  • If you right-click the existing geodatabase in ArcCatalog or other ArcGIS application, select Export -> Export XML Workspace Document. Make sure to select "Data and Schema" and enable all layers in the GDB. Then create an empty personal geodatabase (mdb) and right-click it, and select Import -> Import XML Workspace Document. Everything in your original GDB should now be in the new one. – PhilippNagel May 28 at 14:15

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