]> granicus.if.org Git - postgis/commitdiff
Added raster's spatially_unique constraint. Ticket #2149. Still needs
authorBborie Park <bkpark at ucdavis.edu>
Fri, 14 Dec 2012 20:26:41 +0000 (20:26 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Fri, 14 Dec 2012 20:26:41 +0000 (20:26 +0000)
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

raster/rt_pg/rtpostgis.sql.in.c

index 9eda2ee890ffb5cc913dc84d46e6b0d505e0a9ff..3b6a07fa914fbb1bb94a08d5b5f17374f8d77b89 100644 (file)
@@ -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,