]> granicus.if.org Git - postgis/commitdiff
Changed name of exclusion constraint to by dynamic due to conflict of
authorBborie Park <bkpark at ucdavis.edu>
Tue, 26 Feb 2013 17:42:12 +0000 (17:42 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Tue, 26 Feb 2013 17:42:12 +0000 (17:42 +0000)
implicit index names. Ticket #2215

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

NEWS
raster/rt_pg/rtpostgis.sql.in.c
raster/test/regress/check_raster_columns.sql
raster/test/regress/check_raster_columns_expected

diff --git a/NEWS b/NEWS
index 869dedf4080e49272b615cceb76b6331fdf3fb30..b65a63ea05f378fdc12c216eb21c01fb0300db9f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -144,6 +144,8 @@ PostGIS 2.1.0
            rasters in ST_Tile()
   - #2203, Changed how rasters with unknown SRID and default geotransform
            are handled when passing to GDAL Warp API
+  - #2215, Fixed raster exclusion constraint for conflicting name of
+           implicit index
 
 PostGIS 2.0.3
 2013/MM/DD
index e3c38b6a5d4480f26f248d59cbe2947b29d4898e..e54b0f173d2a7b1362caa3cc288b921d98f4b34f 100644 (file)
@@ -6583,7 +6583,7 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_spatially_unique(rastschema na
                END IF;
                fqtn := fqtn || quote_ident($2);
 
-               cn := 'enforce_spatially_unique_' || $3;
+               cn := 'enforce_spatially_unique_' || quote_ident($2) || '_'|| $3;
 
                sql := 'ALTER TABLE ' || fqtn ||
                        ' ADD CONSTRAINT ' || quote_ident(cn) ||
@@ -6594,9 +6594,29 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_spatially_unique(rastschema na
        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
+       RETURNS boolean AS $$
+       DECLARE
+               cn text;
+       BEGIN
+               SELECT
+                       s.conname INTO cn
+               FROM pg_class c, pg_namespace n, pg_attribute a, pg_constraint s, pg_index idx, pg_operator op
+               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 s.contype = 'x'
+                       AND 0::smallint = ANY (s.conkey)
+                       AND idx.indexrelid = s.conindid
+                       AND pg_get_indexdef(idx.indexrelid, 1, true) LIKE '(' || quote_ident($3) || '::geometry)'
+                       AND s.conexclop[1] = op.oid
+                       AND op.oprname = '=';
+
+               RETURN _drop_raster_constraint($1, $2, cn); 
+       END;
+       $$ LANGUAGE 'plpgsql' VOLATILE STRICT
        COST 100;
 
 CREATE OR REPLACE FUNCTION _raster_constraint_info_coverage_tile(rastschema name, rasttable name, rastcolumn name)
index 3184ec3e0331fde50575c5e37b9f9cb92f59a185..2222ed7670f3b24b715aa80b4fdeb6cad6ee0bd5 100644 (file)
@@ -106,5 +106,12 @@ SELECT make_test_raster(0, 3, 3, 1, 0);
 SELECT DropRasterConstraints(current_schema(), 'test_raster_columns', 'rast'::name, 'regular_blocking');
 SELECT r_table_name, r_raster_column, srid, scale_x, scale_y, blocksize_x, blocksize_y, same_alignment, regular_blocking, num_bands, pixel_types, nodata_values, ST_AsEWKT(extent) FROM raster_columns WHERE r_table_name = 'test_raster_columns';
 
+-- ticket #2215
+CREATE TABLE test_raster_columns_2 AS
+       SELECT rid, rast FROM test_raster_columns;
+SELECT AddRasterConstraints(current_schema(), 'test_raster_columns_2', 'rast'::name);
+SELECT AddRasterConstraints(current_schema(), 'test_raster_columns', 'rast'::name, 'regular_blocking');
+DROP TABLE IF EXISTS test_raster_columns_2;
+
 DROP FUNCTION make_test_raster(integer, integer, integer, double precision, double precision, double precision, double precision, double precision, double precision);
 DROP TABLE IF EXISTS test_raster_columns;
index 6bc4b06597154a00c3c4a413d45ecac83adbf3b5..2c05c8fcb6a29d9b9056fe46d6d1f246666a3170 100644 (file)
@@ -15,7 +15,9 @@ t
 t
 t
 test_raster_columns|rast|0|1|1|3|3|t|t|1|{8BUI}|{0}|POLYGON((3 0,0 0,0 3,0 6,3 6,6 6,6 3,6 0,3 0))
-ERROR:  conflicting key value violates exclusion constraint "enforce_spatially_unique_rast"
+ERROR:  conflicting key value violates exclusion constraint "enforce_spatially_unique_test_raster_columns_rast"
 ERROR:  new row for relation "test_raster_columns" violates check constraint "enforce_coverage_tile_rast"
 t
 test_raster_columns|rast|0|1|1|3|3|t|f|1|{8BUI}|{0}|POLYGON((3 0,0 0,0 3,0 6,3 6,6 6,6 3,6 0,3 0))
+t
+t