[postgis-tickets] r15243 - add raster constraint max extent exceeds array size limit

Regina Obe lr at pcorp.us
Mon Nov 21 22:58:02 PST 2016


Author: robe
Date: 2016-11-21 22:58:02 -0800 (Mon, 21 Nov 2016)
New Revision: 15243

Modified:
   trunk/raster/rt_pg/rtpostgis.sql.in
Log:
add raster constraint max extent exceeds array size limit
references #3501 for trunk (PostGIS 2.4)

Modified: trunk/raster/rt_pg/rtpostgis.sql.in
===================================================================
--- trunk/raster/rt_pg/rtpostgis.sql.in	2016-11-21 15:27:19 UTC (rev 15242)
+++ trunk/raster/rt_pg/rtpostgis.sql.in	2016-11-22 06:58:02 UTC (rev 15243)
@@ -7138,7 +7138,7 @@
 		fqtn text;
 		cn name;
 		sql text;
-		attr text;
+		attr text; srid integer;
 	BEGIN
 		fqtn := '';
 		IF length($1) > 0 THEN
@@ -7146,23 +7146,31 @@
 		END IF;
 		fqtn := fqtn || quote_ident($2);
 
+		sql := 'SELECT @extschema at .ST_SRID('
+            || quote_ident($3)
+      || ') FROM '
+            || fqtn
+            || ' LIMIT 1;';
+    EXECUTE sql INTO srid;
+    
 		cn := 'enforce_max_extent_' || $3;
 
-		sql := 'SELECT @extschema at .st_ashexewkb( @extschema at .st_envelope( @extschema at .st_union( @extschema at .st_envelope('
+		sql := 'SELECT @extschema at .st_ashexewkb( @extschema at .st_setsrid( @extschema at .st_extent( @extschema at .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 at .st_envelope('
 			|| quote_ident($3)
-			|| ') @ ''' || attr || '''::geometry)';
+			|| ') @ ''' || attr || '''::geometry) NOT VALID';
 		RETURN  @extschema at ._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



More information about the postgis-tickets mailing list