Sig,<br><br>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.<br>Also check that the primary key column in the postgis table is of type serial and not just integer.<br>
<br><div class="gmail_quote">On Tue, Dec 13, 2011 at 3:43 AM, Luca Sigfrido Percich <span dir="ltr"><<a href="mailto:sigfrido@tiscali.it">sigfrido@tiscali.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Hi Chaitanya,<br>
<br>
I've made several tests, here are the results (the shapefile has a<br>
id_arco integer field which is the true primary key):<br>
<br>
1. ogr2ogr -overwrite (re)creates the table and adds a<br>
ogc_fid serial NOT NULL primary key<br>
and the original PK field ("id_arco") is being correctly populated<br>
<br>
2. ogr2ogr -overwrite --config PGSQL_OGR_FID id_arco<br>
has no effect, ogc_fid is still being created along with id_arco<br>
<br>
3. on existing PG table with id_arco integer primary key,<br>
ogr2ogr -append -update<br>
<br>
with or without --config PGSQL_OGR_FID id_arco<br>
gives again the error:<br>
<div class="im"><br>
ERROR 1: INSERT command for new feature failed.<br>
</div>ERROR: null value in column "id_arco" violates not-null constraint<br>
<br>
Command: INSERT INTO "t_cmi_archi" ("geom" , "id_fermata", "id_ferma0")<br>
VALUES (<br>
<br>
As you can see, the column "id_arco" does not appear in the insert.<br>
<br>
4. on existing PG table, with an additional column<br>
fake_id serial primary key<br>
ogr2ogr -append -update works, and the original PK field ("id_arco") is<br>
being correctly populated<br>
<br>
It is clear that the PostGIS driver automatically adds a OGC_FID serial<br>
primary key when (re)creating the layer, but can only work with already<br>
existing tables/primary keys if the PK values are generated by the<br>
server.<br>
<br>
Moreover it is not clear how and if the configuration option<br>
PGSQL_OGR_FID works.<br>
<br>
Many thanks,<br>
<br>
Sig<br>
<br>
<br>
Il giorno mar, 13/12/2011 alle 00.12 +0530, Chaitanya kumar CH ha<br>
scritto:<br>
<div class="HOEnZb"><div class="h5">> Sig,<br>
><br>
> Can you check if the fid column names match?<br>
><br>
> On Mon, Dec 12, 2011 at 11:25 PM, Luca Sigfrido Percich<br>
> <<a href="mailto:sigfrido@tiscali.it">sigfrido@tiscali.it</a>> wrote:<br>
> Hi All,<br>
><br>
> I'm using ogr2ogr to load a shapefile into an already existing<br>
> empty<br>
> PostGIS table, which has a primary key constraint on an<br>
> integer column.<br>
><br>
> All the row in the shapefile contain valid unique values for<br>
> the PK<br>
> column, but when loading the shape with<br>
><br>
> ogr2ogr -append -update -a_srs EPSG:3003 -f 'PostgreSQL'<br>
> "PG:host=$HOST<br>
> dbname=$DATABASE user=$USER active_schema=$SCHEMA"<br>
> "$PATH_IN_SHP/$SHP_FERMATE" -nlt Polygon -nln t_cmi_fermate<br>
><br>
> I get the following error:<br>
><br>
> ERROR 1: INSERT command for new feature failed.<br>
> ERROR: null value in column "id_fermata" violates not-null<br>
> constraint<br>
><br>
> I also tried the --config PG_USE_COPY YES, and I get:<br>
> ERROR 1: COPY statement failed.<br>
><br>
> I figured out that when ogr2ogr/PG finds a primary key, it<br>
> assumes that<br>
> it is an autoinc or serial column and does not provide the<br>
> values from<br>
> the source dataset for the INSERT or COPY instruction.<br>
><br>
> If i drop the PK constraint from PostGIS, and reissue the<br>
> ogr2ogr<br>
> command, the shape gets loaded with no errors. So a temporary<br>
> workaround<br>
> is to drop the PK constraint, load data and re-create the<br>
> constraint.<br>
><br>
> Is this the expected behaviour?<br>
><br>
> I must add that I did the same on a SQLite/Spatialite DB, and<br>
> data got<br>
> loaded without raising this error.<br>
><br>
> Thank you for your attention<br>
><br>
> Sig<br>
><br>
><br>
><br>
> _____________<br>
> PRIVACY<br>
> Le informazioni contenute in questo messaggio sono riservate e<br>
> confidenziali. Il loro utilizzo e' consentito esclusivamente<br>
> al destinatario del messaggio, per le finalità indicate nel<br>
> messaggio stesso. Qualora Lei non fosse la persona a cui il<br>
> presente messaggio è destinato, La invitiamo ad eliminarlo dal<br>
> Suo Sistema e a distruggere le varie copie o stampe, dandone<br>
> gentilmente comunicazione all’indirizzo mail del mittente.<br>
> Ogni utilizzo improprio e' contrario ai principi del D.lgs<br>
> 196/03 e alla legislazione europea (Direttiva 2002/58/CE).<br>
><br>
> PRIVACY<br>
> Le informazioni contenute in questo messaggio sono riservate e<br>
> confidenziali. Il loro utilizzo e' consentito esclusivamente<br>
> al destinatario del messaggio, per le finalità indicate nel<br>
> messaggio stesso. Qualora Lei non fosse la persona a cui il<br>
> presente messaggio è destinato, La invitiamo ad eliminarlo dal<br>
> Suo Sistema e a distruggere le varie copie o stampe, dandone<br>
> gentilmente comunicazione all’indirizzo mail del mittente.<br>
> Ogni utilizzo improprio e' contrario ai principi del D.lgs<br>
> 196/03 e alla legislazione europea (Direttiva 2002/58/CE).<br>
> _______________________________________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
><br>
><br>
><br>
> --<br>
> Best regards,<br>
> Chaitanya kumar CH.<br>
><br>
> <a href="tel:%2B91-9494447584" value="+919494447584">+91-9494447584</a><br>
> 17.2416N 80.1426E<br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Chaitanya kumar CH.<br><br>+91-9494447584<br>17.2416N 80.1426E<br>