I'm trying to update a PostGIS table using the SetField() method in python. The table is imported from a shapefile with pgsql2shp so it has a gid field, which can be used as FID or primary key.

However, when executing SetField(), I get an error saying:

Error 1: Unable to update features in tables without a recognised FID column. 

I tried different things. The only thing that allows updating is to externally add and populate a new column called ogc_fid. Even adding a 'fid' column won't do.

Is there a way to tell ogr/gdal (as of gdal2.1.3) in the python code itself that an existing field such as gid is the FID column?

  • 1
    Why don't you add primary key constraint to your existing gid field? – user30184 Jul 29 '17 at 8:23
  • @user30184, the test table was imported using shp2pgsql directly. I didn't want to change the table for a specific client package (unless I have to). – tinlyx Jul 29 '17 at 10:08
  • Every spatial table should really have a primary key. Could you try to run shp2psql with -I flag? That should force gid to primary key. If gid is already a PK but GDAL does not recognize it there may be a bug. – user30184 Jul 29 '17 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.