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">&lt;<a href="mailto:sigfrido@tiscali.it">sigfrido@tiscali.it</a>&gt;</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&#39;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 (&quot;id_arco&quot;) 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 &quot;id_arco&quot; violates not-null constraint<br>
<br>
Command: INSERT INTO &quot;t_cmi_archi&quot; (&quot;geom&quot; , &quot;id_fermata&quot;, &quot;id_ferma0&quot;)<br>
VALUES (<br>
<br>
As you can see, the column &quot;id_arco&quot; 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 (&quot;id_arco&quot;) 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">&gt; Sig,<br>
&gt;<br>
&gt; Can you check if the fid column names match?<br>
&gt;<br>
&gt; On Mon, Dec 12, 2011 at 11:25 PM, Luca Sigfrido Percich<br>
&gt; &lt;<a href="mailto:sigfrido@tiscali.it">sigfrido@tiscali.it</a>&gt; wrote:<br>
&gt;         Hi All,<br>
&gt;<br>
&gt;         I&#39;m using ogr2ogr to load a shapefile into an already existing<br>
&gt;         empty<br>
&gt;         PostGIS table, which has a primary key constraint on an<br>
&gt;         integer column.<br>
&gt;<br>
&gt;         All the row in the shapefile contain valid unique values for<br>
&gt;         the PK<br>
&gt;         column, but when loading the shape with<br>
&gt;<br>
&gt;         ogr2ogr -append -update -a_srs EPSG:3003 -f &#39;PostgreSQL&#39;<br>
&gt;         &quot;PG:host=$HOST<br>
&gt;         dbname=$DATABASE user=$USER active_schema=$SCHEMA&quot;<br>
&gt;         &quot;$PATH_IN_SHP/$SHP_FERMATE&quot; -nlt Polygon  -nln t_cmi_fermate<br>
&gt;<br>
&gt;         I get the following error:<br>
&gt;<br>
&gt;         ERROR 1: INSERT command for new feature failed.<br>
&gt;         ERROR:  null value in column &quot;id_fermata&quot; violates not-null<br>
&gt;         constraint<br>
&gt;<br>
&gt;         I also tried the --config PG_USE_COPY YES, and I get:<br>
&gt;         ERROR 1: COPY statement failed.<br>
&gt;<br>
&gt;         I figured out that when ogr2ogr/PG finds a primary key, it<br>
&gt;         assumes that<br>
&gt;         it is an autoinc or serial column and does not provide the<br>
&gt;         values from<br>
&gt;         the source dataset for the INSERT or COPY instruction.<br>
&gt;<br>
&gt;         If i drop the PK constraint from PostGIS, and reissue the<br>
&gt;         ogr2ogr<br>
&gt;         command, the shape gets loaded with no errors. So a temporary<br>
&gt;         workaround<br>
&gt;         is to drop the PK constraint, load data and re-create the<br>
&gt;         constraint.<br>
&gt;<br>
&gt;         Is this the expected behaviour?<br>
&gt;<br>
&gt;         I must add that I did the same on a SQLite/Spatialite DB, and<br>
&gt;         data got<br>
&gt;         loaded without raising this error.<br>
&gt;<br>
&gt;         Thank you for your attention<br>
&gt;<br>
&gt;         Sig<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         _____________<br>
&gt;         PRIVACY<br>
&gt;         Le informazioni contenute in questo messaggio sono riservate e<br>
&gt;         confidenziali. Il loro utilizzo e&#39; consentito esclusivamente<br>
&gt;         al destinatario del messaggio, per le finalità indicate nel<br>
&gt;         messaggio stesso. Qualora Lei non fosse la persona a cui il<br>
&gt;         presente messaggio è destinato, La invitiamo ad eliminarlo dal<br>
&gt;         Suo Sistema e a distruggere le varie copie o stampe, dandone<br>
&gt;         gentilmente comunicazione all’indirizzo mail del mittente.<br>
&gt;         Ogni utilizzo improprio e&#39; contrario ai principi del D.lgs<br>
&gt;         196/03 e alla legislazione europea (Direttiva 2002/58/CE).<br>
&gt;<br>
&gt;         PRIVACY<br>
&gt;         Le informazioni contenute in questo messaggio sono riservate e<br>
&gt;         confidenziali. Il loro utilizzo e&#39; consentito esclusivamente<br>
&gt;         al destinatario del messaggio, per le finalità indicate nel<br>
&gt;         messaggio stesso. Qualora Lei non fosse la persona a cui il<br>
&gt;         presente messaggio è destinato, La invitiamo ad eliminarlo dal<br>
&gt;         Suo Sistema e a distruggere le varie copie o stampe, dandone<br>
&gt;         gentilmente comunicazione all’indirizzo mail del mittente.<br>
&gt;         Ogni utilizzo improprio e&#39; contrario ai principi del D.lgs<br>
&gt;         196/03 e alla legislazione europea (Direttiva 2002/58/CE).<br>
&gt;         _______________________________________________<br>
&gt;         gdal-dev mailing list<br>
&gt;         <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
&gt;         <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Best regards,<br>
&gt; Chaitanya kumar CH.<br>
&gt;<br>
&gt; <a href="tel:%2B91-9494447584" value="+919494447584">+91-9494447584</a><br>
&gt; 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>