From: Bborie Park Date: Fri, 14 Dec 2012 20:26:41 +0000 (+0000) Subject: Added raster's spatially_unique constraint. Ticket #2149. Still needs X-Git-Tag: 2.1.0beta2~298 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=094543e095ef5609b123abf0b4d2d364bf80b880;p=postgis Added raster's spatially_unique constraint. Ticket #2149. Still needs regression tests but won't happen until regular_blocking is finished. git-svn-id: http://svn.osgeo.org/postgis/trunk@10833 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index 9eda2ee89..3b6a07fa9 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -6433,6 +6433,53 @@ CREATE OR REPLACE FUNCTION _drop_raster_constraint_alignment(rastschema name, ra LANGUAGE 'sql' VOLATILE STRICT COST 100; +CREATE OR REPLACE FUNCTION _raster_constraint_info_spatially_unique(rastschema name, rasttable name, rastcolumn name) + RETURNS boolean AS $$ + SELECT + TRUE + FROM pg_class c, pg_namespace n, pg_attribute a, pg_constraint s + WHERE n.nspname = $1 + AND c.relname = $2 + AND a.attname = $3 + AND a.attrelid = c.oid + AND s.connamespace = n.oid + AND s.conrelid = c.oid + AND a.attnum = ANY (s.conkey) + AND s.contype = 'u'; + $$ LANGUAGE sql STABLE STRICT + COST 100; + +CREATE OR REPLACE FUNCTION _add_raster_constraint_spatially_unique(rastschema name, rasttable name, rastcolumn name) + RETURNS boolean AS $$ + DECLARE + fqtn text; + cn name; + sql text; + attr text; + meta record; + BEGIN + fqtn := ''; + IF length($1) > 0 THEN + fqtn := quote_ident($1) || '.'; + END IF; + fqtn := fqtn || quote_ident($2); + + cn := 'enforce_spatially_unique_' || $3; + + sql := 'ALTER TABLE ' || fqtn || + ' ADD CONSTRAINT ' || quote_ident(cn) || + ' EXCLUDE ((' || quote_ident($3) || '::geometry) WITH =)'; + RETURN _add_raster_constraint(cn, sql); + END; + $$ LANGUAGE 'plpgsql' VOLATILE STRICT + COST 100; + +CREATE OR REPLACE FUNCTION _drop_raster_constraint_spatially_unique(rastschema name, rasttable name, rastcolumn name) + RETURNS boolean AS + $$ SELECT _drop_raster_constraint($1, $2, 'enforce_spatially_unique_' || $3) $$ + LANGUAGE 'sql' VOLATILE STRICT + COST 100; + CREATE OR REPLACE FUNCTION _raster_constraint_info_regular_blocking(rastschema name, rasttable name, rastcolumn name) RETURNS boolean AS $$ @@ -6934,7 +6981,7 @@ CREATE OR REPLACE FUNCTION AddRasterConstraints ( blocksize_x boolean DEFAULT TRUE, blocksize_y boolean DEFAULT TRUE, same_alignment boolean DEFAULT TRUE, - regular_blocking boolean DEFAULT FALSE, -- false as regular_blocking is not a usable constraint + regular_blocking boolean DEFAULT FALSE, -- false as regular_blocking is an enhancement num_bands boolean DEFAULT TRUE, pixel_types boolean DEFAULT TRUE, nodata_values boolean DEFAULT TRUE, @@ -7008,7 +7055,7 @@ CREATE OR REPLACE FUNCTION AddRasterConstraints ( blocksize_x boolean DEFAULT TRUE, blocksize_y boolean DEFAULT TRUE, same_alignment boolean DEFAULT TRUE, - regular_blocking boolean DEFAULT FALSE, -- false as regular_blocking is not a usable constraint + regular_blocking boolean DEFAULT FALSE, -- false as regular_blocking is an enhancement num_bands boolean DEFAULT TRUE, pixel_types boolean DEFAULT TRUE, nodata_values boolean DEFAULT TRUE,