[gdal-dev] ogr2ogr, preserve_fid and Postgres sequences

César Martínez cmartinez at scolab.es
Thu Sep 7 08:05:36 PDT 2017


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 ;

César


>
> -Jukka Rahkonen-
>
>
>
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev




-- 
SCOLAB
http://scolab.es
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170907/4708a020/attachment.html>


More information about the gdal-dev mailing list