[gdal-dev] Inserting into PostGIS table with primary key using ogr2ogr

Even Rouault even.rouault at mines-paris.org
Tue Dec 13 07:18:06 EST 2011


Selon Luca Sigfrido Percich <sigfrido at tiscali.it>:

>
> Hi Chaitanya,
>
> I understand, thank you. Those options are not relevant because I'm
> appending to an existing PostGIS table.
>
> Summing up: currently it is not possible to append rows to a PostGIS
> table if this table has a primary key which is not incremented
> server-side, because the values of the primary key column are not copied
> from the source dataset into the postGIS PK column.
> I tried also with the -sql option including the pk column, with no luck.

Yes, when the driver detects a PK column, it considers it as the FID column,
which is a particular column, different from the regular columns. So it will be
ommited in the INSERT statements, unless the feature to be inserted as a FID
value set. Which is not the case by default when using ogr2ogr.

I'd suggest you to try to add the -preserve_fid option to ogr2ogr.

>
> Is this the expected behaviour? IMHO all the (selected) columns from the
> source dataset should be copied in to the destination, leaving to the
> server the task of eventually complaining about duplicate or malformed
> keys.
>
> Moreover, this does not happen with SQLite, where all the columns get
> copied regardless they are part of a PK constraint, so at least it's an
> inconsistency.

Looking at the code (in trunk), it isn't obvious that the PG and SQLite driver
would behave differently, but I haven't actually tried, and if you are not using
trunk, it is possible that there have been changes that might have altered the
behaviour w.r.t older GDAL/OGR versions.

>
> I will file a bug for this.
>
> Thank you again
>
> Sig
>
> Il giorno mar, 13/12/2011 alle 10.06 +0530, Chaitanya kumar CH ha
> scritto:
> > Sig,
> >
> > The configuration option PGSQL_OGR_FID is only used for reading a
> > postgis table. Use the creation option FID to specify the FID column
> > to create.
> > Also check that the primary key column in the postgis table is of type
> > serial and not just integer.
>
>
> _____________
> PRIVACY
> Le informazioni contenute in questo messaggio sono riservate e confidenziali.
> Il loro utilizzo e' consentito esclusivamente al destinatario del messaggio,
> per le finalità indicate nel messaggio stesso. Qualora Lei non fosse la
> persona a cui il presente messaggio è destinato, La invitiamo ad eliminarlo
> dal Suo Sistema e a distruggere le varie copie o stampe, dandone gentilmente
> comunicazione all’indirizzo mail del mittente. Ogni utilizzo improprio e'
> contrario ai principi del D.lgs 196/03 e alla legislazione europea (Direttiva
> 2002/58/CE).
>
> PRIVACY
> Le informazioni contenute in questo messaggio sono riservate e confidenziali.
> Il loro utilizzo e' consentito esclusivamente al destinatario del messaggio,
> per le finalità indicate nel messaggio stesso. Qualora Lei non fosse la
> persona a cui il presente messaggio è destinato, La invitiamo ad eliminarlo
> dal Suo Sistema e a distruggere le varie copie o stampe, dandone gentilmente
> comunicazione all’indirizzo mail del mittente. Ogni utilizzo improprio e'
> contrario ai principi del D.lgs 196/03 e alla legislazione europea (Direttiva
> 2002/58/CE).
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>




More information about the gdal-dev mailing list