[gdal-dev] ogr2ogr, preserve_fid and Postgres sequences

Even Rouault even.rouault at spatialys.com
Thu Sep 7 08:41:11 PDT 2017


On jeudi 7 septembre 2017 17:05:36 CEST César Martínez wrote:
> Hi Jukka, see answer inline:
> 
> 2017-09-07 16:48 GMT+02:00 jratike80 <jukka.rahkonen at maanmittauslaitos.fi>:
> > Hi César,
> > 
> > What are the problems you face when editing such layer?
> 
> If you later try to add a new record to the layer without providing an id,
> it will raise an error, defeating the purpose of having a serial PK. For
> instance:
> 
> INSERT INTO test1 (wkb_geometry)
> VALUES (ST_GeomFromText('MULTIPOINT(-5.34510248270791 36.1506091987899)',
> 4258)) ;
> 
> ERROR: duplicate key value violates unique constraint "test1_pkey"
> SQL state: 23505
> Detail: Key (ogc_fid)=(1) already exists.
> 
> They you must provide the ogc_fid by hand:
> 
> INSERT INTO test1 (ogc_fid, wkb_geometry)
> VALUES (102, ST_GeomFromText('MULTIPOINT(-5.34510248270791
> 36.1506091987899)', 4258)) ;
> 
> > Do you have an
> > alternative suggestion about what to do for the sequence?
> 
> The sequence should be initialized in the same way as it is done when
> -preserve_fid is not provided.
> For the layer & sequence in the example, the following SQL statement would
> work:
> 
> SELECT set_val('test1_ogc_fid_seq', max(ogc_fid)) FROM test1 ;

Would you mind opening a ticket in Trac about that
https://trac.osgeo.org/gdal/newticket

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170907/28e02fcf/attachment.html>


More information about the gdal-dev mailing list