[gdal-dev] RE: Copying FIDs into existing PG schema

Jeremy Palmer JPalmer at linz.govt.nz
Tue Feb 7 17:38:10 EST 2012


Any chance? Should I log a bug report?

> 
> Hi
> 
> When using the config PG_USE_COPY option the copy command does not include the
> destination FID in the field list. In my case the destination FID field is a primary key
> with a not null constraint, so the copy fails.
> 
> e.g.
> 
> ogr2ogr --config PG_USE_COPY TRUE -append -preserve_fid -f "PostgreSQL"
> "PG:host=localhost user=myuser dbname=my_db" test.vrt -lco
> GEOMETRY_NAME=shape -nln test3 -select id,data1,data2
> 
> when the destination table looks like this:
> 
> CREATE TABLE test3
> (
>   id integer NOT NULL PRIMARY KEY,
>   data1 TEXT,
>   data2 TEXT,
>   shape geometry
> );
> 
> However when I don't use the PG_USE_COPY option and the driver uses plain SQL
> inserts it works e.g:
> 
> ogr2ogr -append -preserve_fid -f "PostgreSQL" "PG:host=localhost user=myuser
> dbname=my_db" test.vrt -lco GEOMETRY_NAME=shape -nln test3 -select
> id,data1,data2
> 
> Looking down into this it seems it has to do with the layers FieldDefn not including the
> FID in its list, and the OGRPGTableLayer::BuildCopyFields() method only adding the
> FID to the copy field list if it's in the layer FieldDefn. While the
> CreateFeatureViaInsert() method only checks if the FID field is set for the layer and
> the feature itself has the FID data set.
> 
> Is there a specific reason for the OGRPGTableLayer::BuildCopyFields (and
> CreateFeatureViaCopy) checking that the field must exist in the layer FieldDefn before
> adding it to the copy field list? Or is this a bug?
> 
> Cheers,
> Jeremy
> 

#####################################################################################

This message contains information, which is confidential and may be subject to legal privilege. 
If you are not the intended recipient, you must not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify us immediately (Phone 0800 665 463 or info at linz.govt.nz) and destroy the original message.
LINZ accepts no responsibility for changes to this email, or for any attachments, after its transmission from LINZ.

Thank You.

#####################################################################################


More information about the gdal-dev mailing list