[gdal-dev] ogr2ogr question

Even Rouault even.rouault at spatialys.com
Mon Dec 21 08:55:11 PST 2020


Matteo,

> I'm really stuck on a ogr2ogr command.
> 
> I've a template.gpkg file with some tables and what I'm trying to do is
> to overwrite some of these tables with some already existing views of a
> PG database.
> 
> The tables and views have the same structure and geometry, basically I'm
> trying to create a my_data.gpkg with the same tables of the
> template.gpkg file, but overwriting some of these tables with the PG
> view contents.
> 
> This is the ogr2ogr command I'm using, but nothing is happening (the
> data.gpkg remains the same of template.gpkg).
> 
> ogr2ogr -f GPKG /home/matteo/Desktop/data.gpkg "PG:dbname='mydb'
> host=myhost port=5432 user='myuser' password='xxxxx' sslmode=disable"
> --config PG_USE_COPY YES -sql "SELECT * FROM "_003"."intap" " -overwrite
> -progress
> 
> (the intap table should be overwritten with the content filtered by the
> -sql statement: "_003"."intap" is the view of PG).
> 
> I search everywhere for a parameter that could solve this problem but I
> didn't find any

If you look at the output of
ogrinfo PG:..... -sql "select ...."
you'll see that the resulting layer is called "sql_statement", so your ogr2ogr 
invokation will overwrite/create a sql_statement table in your GPKG. You want 
to add -nln intap to rename this SQL result layer.
And -overwrite deletes and recreates the table from scratch, so if you've 
customized your template with CHECKs, FOREIGN KEYs etc, they will be lost. If 
the target table in the template is empty, you can just use -append instead of 
-overwrite.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list