Hi,<div><br></div><div>-d option will try to drop the table, will display an error message if it can't, but after that, table is created and populated.</div><div>The drop is done outside the main creation/insertion transaction.</div>
<div><br></div><div>So if you do not depend on ERROR message generated by your script, it should be fine to always call shp2pgsql with the -d option.</div><div><br></div><div>(by the way, you really want to generate .sql files on your disk ? If you have a lot of shapefiles and/or big shapefiles, your script will generate potentially big sql files.  </div>
<div>you can pipe the output of shp2pgsql to psql to avoid this step)</div><div><br></div><div>By updating, you mean erase and replace ? or update existing tables by appending data if needed ?</div><div><br></div><div>Nicolas</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On 28 November 2012 16:53, Mark Volz <span dir="ltr"><<a href="mailto:MarkVolz@co.lyon.mn.us" target="_blank">MarkVolz@co.lyon.mn.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello<br>
<br>
I would like to set up an windows batch file that will automatically update PostGIS from a directory of shapefiles.  I have a couple potential code samples, and would appreciate comments.   Thanks<br>
<br>
Example 1  - This code will create new tables in postgis from tables, however it doesn't seem to replace existing tables with existing shapefiles:<br>
for %%f in (*.shp) do shp2pgsql -c -I -s 103749 -W LATIN1 %%f %%~nf > %%~nf.sql<br>
for %%f in (*.sql) do psql -p 5432 -w -U postgres --dbname postgis20 -f %%f<br>
<br>
Example 2 - This code will replace existing tables, however it doesn't seem to create new tables.<br>
for %%f in (*.shp) do shp2pgsql -d -I -s 103749 -W LATIN1 %%f %%~nf > %%~nf.sql<br>
for %%f in (*.sql) do psql -p 5432 -w -U postgres --dbname postgis20 -f %%f<br>
<br>
Example 3 - I also came across this code as well that will delete all the tables in a database,  which then I could turn around and use shp2pgsql with the -c option.  However I don't want it to take down the spatial reference table:<br>

psql  -U postgres -t -d postgis20 -c "SELECT 'DROP TABLE ' || n.nspname || '.' || c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind = 'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid)" >/tmp/droptables<br>

psql  -d postgis20 -f /tmp/droptables<br>
<br>
Questions:<br>
1)  Is there a way to protect the spatial reference table so that it would drop when using psql?<br>
2)  Are my Assumptions about the -c and -d flag correct?   Where -c will work only if the table is new, and -d will work only if the table already exists?<br>
3)  Does anyone have any automatic update scripts?<br>
<br>
Thank You<br>
<br>
Mark Volz<br>
GIS Specialist<br>
<br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>