OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.91k stars 2.55k forks source link

gpkg_ogr_contents.feature_count can not be updated when started with empty table #11274

Open andreglauser opened 2 days ago

andreglauser commented 2 days ago

What is the bug?

If a table is created empty and features are added afterwards gpkg_ogr_contents.feature_count can not be updated because NULL + 1 results to "NULL"

In a GPKG the column feature_count of the table gpkg_ogr_contents is created with a default of NULL. For new tables triggers are created to manage gpkg_ogr_contents.feature_count with ..SET feature_count = feature_count + 1... In case the existing value of feature_count is NULL the triggers are not able to increment the number from NULL to 1.

Steps to reproduce the issue

With QGIS: Create a Geopackage with an new layer. Add some features. Check the data of gpkg_ogr_contents.

With follwing example for the table "new_table" the behaviour can be simulated.

SELECT 
    feature_count + 1 
FROM gpkg_ogr_contents
WHERE lower(table_name) = lower('new_table')

Versions and provenance

Windows 11 GDAL 3.9.3, released 2024/10/07 QGIS 3.34 and 3.40

Additional context

No response