Using ogr2ogr within python (and Windows 10), I can upload a shapefile to Postgres as a new table. However, my shapefile is made of 10 parts (10 shapefiles). I can upload the first .shp but when trying to append the next .shp to the table, I get an 'Error: layer already exists'. Even though I'm using the -append tag in my command.
Here is my command for the first shapefile AND subequent shapefiles to append:
ogr2ogr -f "PostgreSQL" PG:"host=url port=5432 dbname=db1 user=username password=password" -append -nln tablename -lco GEOMETRY_NAME=shape -lco SCHEMA=schema1 "D:\path\shapefile(1,2,3...).shp" -progress -nlt MULTIPOLYGON
or more specifically (as I'm using python):
from subprocess import call
command = r'ogr2ogr -f "PostgreSQL" PG:"host=url port=5432 dbname=db1 user=username password=password" -append -nln tablename -lco GEOMETRY_NAME=shape -lco SCHEMA=schema1 "D:\path\shapefile(1,2,3...).shp" -progress -nlt MULTIPOLYGON'
call(command)
and the error that occurs when trying to append the 2nd shapefile to the newly created table:
ERROR 1: Layer schema1.tablename already exists, CreateLayer failed.
Use the layer creation option OVERWRITE=YES to replace it.
ERROR 1: Terminating translation prematurely after failed
translation of layer shapefile2 (use -skipfailures to skip errors)
-updateflag. check my answer here for an easily customizable Bash/CMD batch import script – geozelot Nov 20 '19 at 17:03-nlnoption – geozelot Nov 20 '19 at 17:19ogr2ogr ... -append -update ...works just fine for me (Ubuntu, Bash). – geozelot Nov 20 '19 at 18:52-in it, which ogr automatically converted to_. For whatever reason that messed with the append behavior. When I changed the dash to an underscore ahead of time, I was able to append to the table – Avocado Mar 17 '22 at 21:17