4

I have a geopackage which contains around 30 files. I want to put a "mmbl_" before the actual file name for all the layers in the said geopackage. Is there a an SQL expression to automate this renaming process in QGIS?

1 Answer 1

5

You must rename layers one by with SQL ALTER TABLE... See https://gdal.org/drivers/vector/gpkg.html. For renaming many layers automatically you should make a script that first gets the list of the tables to rename. I suppose that you interested in just the spatial tables so you can get the list with

SELECT table_name from gpkg_contents

For renaming you can use ogrinfo. The command would look like

ogrinfo -sql "ALTER TABLE first_table RENAME TO mmbl_first_table" my_geopackage.gpkg

You must not try to rename the table with generic SQLite tools and native RENAME TO https://www.sqlite.org/lang_altertable.html or otherwise you will break the geopackage. The native alter table can rename the table and update the triggers, but it does not update the references in the metadata tables gpkg_contents, gpkg_geometry_columns, gpkg_extensions, and others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.