Context
I'm trying to update a PostgreSQL+PostGIS table from an ESRI Shapefile using the ogr2ogr
tool from gdal.
The Shapefile is being updated from external sources on a regular basis.
I don't want to append its content, I prefer starting again from scratch.
This is the command I run for the moment;
ogr2ogr \
-lco OVERWRITE=yes \
-nlt PROMOTE_TO_MULTI \
-nln vector_data.lines \
-f "PostgreSQL" \
PG:"host=localhost user=username dbname=my_database" \
-a_srs EPSG:4326 "${shapedir}/el_lines.shp"
Issues
1:
I get this warning message:
Warning 1: Layer creation options ignored since an existing layer is
being appended to.
And the features are being append to the table, hence doubling the number of rows.
2:
If I add the -overwrite
option, features (i.e. records in the table) are being successfully updated, as I expect, but the downside is I lose all the views and relations which have a link to the table I want to update. Needless to say I don't want to lose these views and relations.
Question
How to wisely use ogr2ogr
so that it builds the table as if it's newly created (such as the really first time I ran ogr2ogr
), but while keeping all relations to this table in the database?
Related questions
Environment
PostgreSQL:
"PostgreSQL 10.12 (Ubuntu 10.12-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, \
compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit"
PostGIS:
"2.4 USE_GEOS=1 USE_PROJ=1 USE_STATS=1"
Gdal:
$ ogr2ogr --version
GDAL 2.4.0, released 2018/12/14