<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Yes, well found.<br>
<br>
I'm not familiar with plpgsql, but I'm sure it's easy to include
some conditional statement. Just check the postgres documentation.<br>
You can also check if you can put the conditional into your SQL
query (something like 'WHERE count(rast) > 0') so that you don't
feed empty rasters to the function.<br>
<br>
all the best,<br>
Tom<br>
<br>
On 19-12-2011 11:13, Andreas Forø Tollefsen wrote:
<blockquote
cite="mid:CAGMz7DmjquAy9S35xrQ7jyVTxFKp_NUzr-yCEy2xmxgbqS8eEg@mail.gmail.com"
type="cite">Line 59 to 77 in the st_summarystatsagg.sql.<br>
Could it be that line 69: ($1).sum / ($1).count leads to division
by zero error if ($1).count is 0?<br>
How could i change this so this is not the case?<br>
<br>
-- raster_summarystatsfinal<br>
-- Final function used by the ST_SummaryStatsAgg aggregate <br>
CREATE OR REPLACE FUNCTION raster_summarystatsfinal(ss
summarystats)<br>
RETURNS summarystats <br>
AS $$<br>
DECLARE<br>
ret summarystats;<br>
BEGIN<br>
ret := (($1).count,<br>
($1).sum,<br>
($1).sum / ($1).count,<br>
null,<br>
($1).min,<br>
($1).max<br>
)::summarystats;<br>
RETURN ret;<br>
END;<br>
$$<br>
LANGUAGE 'plpgsql';<br>
<br>
<div class="gmail_quote">2011/12/19 Andreas Forø Tollefsen <span
dir="ltr"><<a moz-do-not-send="true"
href="mailto:andreasft@gmail.com">andreasft@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Updated to
latest trunk, and now it works.<br>
However, I ran into a new "division by zero" error. This halts
the query.<br>
Could it be that something is divided by integer rather than
decimal in the query, or what else causes this:<br>
<br>
ERROR: division by zero<br>
CONTEXT: PL/pgSQL function "raster_summarystatsfinal" line 5
at assignment<br>
<br>
********** Error **********<br>
<br>
ERROR: division by zero<br>
SQL state: 22012<br>
Context: PL/pgSQL function "raster_summarystatsfinal" line 5
at assignment<br>
<br>
Best,<br>
<font color="#888888">Andreas</font><br>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>