]> granicus.if.org Git - postgis/commitdiff
Changed blocksize constraint to permit multiple possible values. Ticket
authorBborie Park <bkpark at ucdavis.edu>
Fri, 14 Dec 2012 20:26:20 +0000 (20:26 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 14 Dec 2012 20:26:20 +0000 (20:26 +0000)
is #2143. We just need a coverage constraint and a spatially unique
constraint to determine regularly blocked.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10831 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rtpostgis.sql.in.c

index 2f96a472afcd8fff5e3ad7ff27ed692710ab6b0f..beb7ba181a925ab6e7b739f54edb54ef472a64e6 100644 (file)
@@ -6231,7 +6231,12 @@ CREATE OR REPLACE FUNCTION _drop_raster_constraint_scale(rastschema name, rastta
 CREATE OR REPLACE FUNCTION _raster_constraint_info_blocksize(rastschema name, rasttable name, rastcolumn name, axis text)
        RETURNS integer AS $$
        SELECT
-               replace(replace(split_part(s.consrc, ' = ', 2), ')', ''), '(', '')::integer
+               CASE
+                       WHEN strpos(s.consrc, 'ANY (ARRAY[') > 0 THEN
+                               split_part((regexp_matches(s.consrc, E'ARRAY\\[(.*?){1}\\]'))[1], ',', 1)::integer
+                       ELSE
+                               replace(replace(split_part(s.consrc, '= ', 2), ')', ''), '(', '')::integer
+                       END
        FROM pg_class c, pg_namespace n, pg_attribute a, pg_constraint s
        WHERE n.nspname = $1
                AND c.relname = $2
@@ -6240,7 +6245,7 @@ CREATE OR REPLACE FUNCTION _raster_constraint_info_blocksize(rastschema name, ra
                AND s.connamespace = n.oid
                AND s.conrelid = c.oid
                AND a.attnum = ANY (s.conkey)
-               AND s.consrc LIKE '%st_' || $4 || '(% = %';
+               AND s.consrc LIKE '%st_' || $4 || '(%= %';
        $$ LANGUAGE sql STABLE STRICT
   COST 100;
 
@@ -6250,7 +6255,8 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_blocksize(rastschema name, ras
                fqtn text;
                cn name;
                sql text;
-               attr int;
+               attrset integer[];
+               attr integer;
        BEGIN
                IF lower($4) != 'width' AND lower($4) != 'height' THEN
                        RAISE EXCEPTION 'axis must be either "width" or "height"';
@@ -6268,9 +6274,12 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_blocksize(rastschema name, ras
                sql := 'SELECT st_' || $4 || '('
                        || quote_ident($3)
                        || ') FROM ' || fqtn
-                       || ' LIMIT 1';
+                       || ' GROUP BY 1 ORDER BY count(*) DESC';
                BEGIN
-                       EXECUTE sql INTO attr;
+                       attrset := ARRAY[]::integer[];
+                       FOR attr IN EXECUTE sql LOOP
+                               attrset := attrset || attr;
+                       END LOOP;
                EXCEPTION WHEN OTHERS THEN
                        RAISE NOTICE 'Unable to get the % of a sample raster', $4;
                        RETURN FALSE;
@@ -6280,7 +6289,7 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_blocksize(rastschema name, ras
                        || ' ADD CONSTRAINT ' || quote_ident(cn)
                        || ' CHECK (st_' || $4 || '('
                        || quote_ident($3)
-                       || ') = ' || attr || ')';
+                       || ') IN (' || array_to_string(attrset, ',') || '))';
                RETURN _add_raster_constraint(cn, sql);
        END;
        $$ LANGUAGE 'plpgsql' VOLATILE STRICT