<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I'd try a different approach to loading your data into the table.<br><br>Try loading your lat/lon values using copy. This will be fastest (specify the field delimiter char): eg: cat <file> | psql -d <db> -c "copy <table> from STDIN with delimiter '?';"<br><br>Then add your geometry column to the table.<br>select addgeometrycolumn(...);<br><br>Then update the geometry column using makepoint<br>update table set geom = setsrid(makepoint(lon,lat));<br><br>Then try to create your unique indexes & work through any duplicates in the db records.<br><br>It is also a good idea to have unique indices as required on natural keys, but have an integer primary key on the table. This is easy to do:<br><br>alter table add column gid serial (or bigserial);<br><br>then make gid the primary key.<br><br>--- On <b>Sat, 4/23/11, Sairam Krishnamurthy
 <i><kmsram420@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Sairam Krishnamurthy <kmsram420@gmail.com><br>Subject: [postgis-users] Unique Constraint on Spatial Point violated<br>To: postgis-users@postgis.refractions.net<br>Cc: "Aditya Kulkarni" <kulkarni.aditya00@gmail.com><br>Date: Saturday, April 23, 2011, 7:10 AM<br><br><div class="plainMail">All,<br><br>I am loading a table from a file. The file is really big and has<br>millions of rows. Table structure is described below:<br><br>lat : double precision (primary key)<br>lon: double precision (primary key)<br>spatialPoint: geometry (unique)<br><br>The file has lines of lat and lon: (lat,lon)<br><br>Since I am loading from a file I cannot load the spatialPoint<br>directly. I have a trigger to call the following function BEFORE<br>INSERT OR UPDATE:<br><br>BEGIN<br>    NEW."spatialPoint"
 := ST_SetSRID(ST_MakePoint(NEW.lon, NEW.lat), 4326);<br>    RETURN new;<br>END<br><br>When I load the table I get unique key constraint on the filed<br>spatialPoint. This happens when I try to load the point<br>"-3.751046|-51.359041". But when I grep for the point in the file only<br>one row exists.<br><br>I am not sure if this is a precision problem in calculting the spatial<br>points from the lat.lon value.<br><br>Can someone help me with this?<br><br>Thanks,<br>Sairam Krishnamurthy<br>+1 612 859 8161<br>_______________________________________________<br>postgis-users mailing list<br><a ymailto="mailto:postgis-users@postgis.refractions.net" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br></div></blockquote></td></tr></table>