--- /dev/null
+-----------------------------------------------------------------------\r
+-- ST_MinPossibleVal\r
+-- Return the smallest value for a given pixeltyp. \r
+-- Should be called like this:\r
+-- SELECT ST_MinPossibleVal(ST_BandPixelType(rast, band))\r
+-----------------------------------------------------------------------\r
+CREATE OR REPLACE FUNCTION ST_MinPossibleVal(pixeltype text)\r
+ RETURNS float8 AS\r
+ $$\r
+ DECLARE\r
+ newval int := 0;\r
+ BEGIN\r
+ newval := CASE \r
+ WHEN pixeltype = '1BB' THEN 0\r
+ WHEN pixeltype = '2BUI' THEN 0\r
+ WHEN pixeltype = '4BUI' THEN 0\r
+ WHEN pixeltype = '8BUI' THEN 0\r
+ WHEN pixeltype = '8BSI' THEN -128\r
+ WHEN pixeltype = '16BUI' THEN 0\r
+ WHEN pixeltype = '16BSI' THEN -32768\r
+ WHEN pixeltype = '32BUI' THEN 0\r
+ WHEN pixeltype = '32BSI' THEN -2147483648\r
+ WHEN pixeltype = '32BF' THEN -2147483648 -- Could not find a function returning the smallest real yet\r
+ WHEN pixeltype = '64BF' THEN -2147483648 -- Could not find a function returning the smallest float8 yet\r
+ END;\r
+ RETURN newval;\r
+ END;\r
+ $$\r
+ LANGUAGE 'plpgsql';\r