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

Luca Sigfrido Percich sigfrido at tiscali.it
Mon Dec 12 12:55:04 EST 2011


Hi All,

I'm using ogr2ogr to load a shapefile into an already existing empty
PostGIS table, which has a primary key constraint on an integer column.

All the row in the shapefile contain valid unique values for the PK
column, but when loading the shape with 

ogr2ogr -append -update -a_srs EPSG:3003 -f 'PostgreSQL' "PG:host=$HOST
dbname=$DATABASE user=$USER active_schema=$SCHEMA"
"$PATH_IN_SHP/$SHP_FERMATE" -nlt Polygon  -nln t_cmi_fermate

I get the following error:

ERROR 1: INSERT command for new feature failed.
ERROR:  null value in column "id_fermata" violates not-null constraint

I also tried the --config PG_USE_COPY YES, and I get:
ERROR 1: COPY statement failed.

I figured out that when ogr2ogr/PG finds a primary key, it assumes that
it is an autoinc or serial column and does not provide the values from
the source dataset for the INSERT or COPY instruction.

If i drop the PK constraint from PostGIS, and reissue the ogr2ogr
command, the shape gets loaded with no errors. So a temporary workaround
is to drop the PK constraint, load data and re-create the constraint.

Is this the expected behaviour?

I must add that I did the same on a SQLite/Spatialite DB, and data got
loaded without raising this error.

Thank you for your attention

Sig



_____________
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).


More information about the gdal-dev mailing list