duckdb_spatial icon indicating copy to clipboard operation
duckdb_spatial copied to clipboard

No option to provide a layername when COPY TO any GDAL multilayer capable format

Open pinkerltm opened this issue 3 months ago • 1 comments

When doing a copy to - for example - a geopackage, the resulting layername inside the Geopackage is the same as the Geopackage Filename. There is no option to give it a certain layername, therefore there is also no option to copy more than one layer to the same Geopackage.

To achieve this, the query would have to forward the -nln parameter of ogr2ogr

pinkerltm avatar Oct 15 '25 10:10 pinkerltm

I believe that it is possible to supply a layer name when exporting to a geopackage.

The SQL below should do just that.

COPY tbl TO 'path/to/file.gpkg'
WITH (FORMAT GDAL, DRIVER'GPKG', LAYER_NAME 'my_custom_layer_name');

However, writing an additional layer to the same file is not possible since the original file is simply overwritten.

COPY tbl TO 'path/to/file.gpkg'
WITH (FORMAT GDAL, DRIVER'GPKG', LAYER_NAME 'my_first_layer_name');

COPY tbl TO 'path/to/file.gpkg'
WITH (FORMAT GDAL, DRIVER'GPKG', LAYER_NAME 'my_second_layer_name');

Only the last layer is present in the geopackage as it gets overwritten for each export. It would be beneficial if appending layers to existing geopackages was a possibility.

fromm1990 avatar Oct 23 '25 10:10 fromm1990