From 230edc7e02ab77650f370ebf6fe0eee8c4169f32 Mon Sep 17 00:00:00 2001 From: Pierre Racine Date: Mon, 10 Sep 2012 18:36:35 +0000 Subject: [PATCH] Fixed the state and final functions when count is zero or initial sum is null git-svn-id: http://svn.osgeo.org/postgis/trunk@10268 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/scripts/plpgsql/st_summarystatsagg.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/raster/scripts/plpgsql/st_summarystatsagg.sql b/raster/scripts/plpgsql/st_summarystatsagg.sql index 89fb9ed24..44c29ffde 100644 --- a/raster/scripts/plpgsql/st_summarystatsagg.sql +++ b/raster/scripts/plpgsql/st_summarystatsagg.sql @@ -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 -- 2.40.0