[gdal-dev] Export PG to GPKG with foreign keys

Even Rouault even.rouault at spatialys.com
Fri Apr 19 02:32:29 PDT 2024


Le 19/04/2024 à 10:25, Matteo Ghetta via gdal-dev a écrit :
> Hi all,
>
> I'm trying to export a PG table with several foreign keys to a 
> geopackage.
>
> What I tried so far are the native QGIS export and the QGIS Processing 
> algorithm "Package layer" with the "Export related layers 
> following..." option activated.
>
> I'm checking ogr2ogr but I cannot see any option to include the export 
> of the foreign keys. Is this option available in order to have a 
> geopackage with the original table with all the other related tables?

In short, no

It might be possible to use the relationship API of 
https://gdal.org/api/gdaldataset_cpp.html#_CPPv4NK11GDALDataset20GetRelationshipNamesE12CSLConstList 
to build something around it. But adding foreign key constraint 
themselves would be tricky as it requires to rewrite the CREATE TABLE.

Even


-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list