]> granicus.if.org Git - postgis/commitdiff
Fixed the state and final functions when count is zero or initial sum is null
authorPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Mon, 10 Sep 2012 18:36:35 +0000 (18:36 +0000)
committerPierre Racine <Pierre.Racine@sbf.ulaval.ca>
Mon, 10 Sep 2012 18:36:35 +0000 (18:36 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10268 b70326c6-7e19-0410-871a-916f4a2858ee

raster/scripts/plpgsql/st_summarystatsagg.sql

index 89fb9ed2477954133299d5d26696b07fbce836f0..44c29ffde5dbd9569dc0bb19623fc419349093c7 100644 (file)
@@ -1,4 +1,4 @@
----------------------------------------------------------------------
+---------------------------------------------------------------------
 -- ST_SummaryStatsAgg AGGREGATE
 -- Compute summary statistics for an aggregation of raster.
 --
@@ -38,7 +38,7 @@ CREATE OR REPLACE FUNCTION raster_summarystatsstate(ss summarystats, rast raster
                     newstats.max)::summarystats;
         ELSE
             ret := (ss.count + newstats.count, 
-                    ss.sum + newstats.sum,
+                    COALESCE(ss.sum,0) + COALESCE(newstats.sum, 0),
                     null,
                     null,
                     least(ss.min, newstats.min), 
@@ -66,7 +66,7 @@ CREATE OR REPLACE FUNCTION raster_summarystatsfinal(ss summarystats)
     BEGIN
         ret := (($1).count,
                 ($1).sum,
-                ($1).sum / ($1).count,
+                CASE WHEN ($1).count = 0 THEN null ELSE ($1).sum / ($1).count END,
                 null,
                 ($1).min,
                 ($1).max