]> granicus.if.org Git - postgis/commitdiff
add raster constraint max extent exceeds array size limit
authorRegina Obe <lr@pcorp.us>
Tue, 22 Nov 2016 06:58:02 +0000 (06:58 +0000)
committerRegina Obe <lr@pcorp.us>
Tue, 22 Nov 2016 06:58:02 +0000 (06:58 +0000)
references #3501 for trunk (PostGIS 2.4)

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

raster/rt_pg/rtpostgis.sql.in

index a50c2bd697e5ed718ac9e566f330a93d16f8a6bf..8cfc6cc36745d1fde190a4c63342d4b5f8e62fb9 100644 (file)
@@ -7138,7 +7138,7 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_extent(rastschema name, rastta
                fqtn text;
                cn name;
                sql text;
-               attr text;
+               attr text; srid integer;
        BEGIN
                fqtn := '';
                IF length($1) > 0 THEN
@@ -7146,23 +7146,31 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_extent(rastschema name, rastta
                END IF;
                fqtn := fqtn || quote_ident($2);
 
+               sql := 'SELECT @extschema@.ST_SRID('
+            || quote_ident($3)
+      || ') FROM '
+            || fqtn
+            || ' LIMIT 1;';
+    EXECUTE sql INTO srid;
+    
                cn := 'enforce_max_extent_' || $3;
 
-               sql := 'SELECT @extschema@.st_ashexewkb( @extschema@.st_envelope( @extschema@.st_union( @extschema@.st_envelope('
+               sql := 'SELECT @extschema@.st_ashexewkb( @extschema@.st_setsrid( @extschema@.st_extent( @extschema@.st_envelope('
                        || quote_ident($3)
-                       || ')))) FROM '
+                       || ')), ' || srid || ')) FROM '
                        || fqtn;
                EXECUTE sql INTO attr;
 
+               -- NOTE: I put NOT VALID to prevent the costly step of validating the constraint
                sql := 'ALTER TABLE ' || fqtn
                        || ' ADD CONSTRAINT ' || quote_ident(cn)
                        || ' CHECK ( @extschema@.st_envelope('
                        || quote_ident($3)
-                       || ') @ ''' || attr || '''::geometry)';
+                       || ') @ ''' || attr || '''::geometry) NOT VALID';
                RETURN  @extschema@._add_raster_constraint(cn, sql);
        END;
        $$ LANGUAGE 'plpgsql' VOLATILE STRICT
-       COST 100;
+       COST 9000;
 
 CREATE OR REPLACE FUNCTION _drop_raster_constraint_extent(rastschema name, rasttable name, rastcolumn name)
        RETURNS boolean AS