From: Bborie Park Date: Tue, 26 Feb 2013 17:42:12 +0000 (+0000) Subject: Changed name of exclusion constraint to by dynamic due to conflict of X-Git-Tag: 2.1.0beta2~192 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c9d0c51865c5faca345e5c910a11d02d9fc449b1;p=postgis Changed name of exclusion constraint to by dynamic due to conflict of implicit index names. Ticket #2215 git-svn-id: http://svn.osgeo.org/postgis/trunk@11117 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 869dedf40..b65a63ea0 100644 --- 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 diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index e3c38b6a5..e54b0f173 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -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) diff --git a/raster/test/regress/check_raster_columns.sql b/raster/test/regress/check_raster_columns.sql index 3184ec3e0..2222ed767 100644 --- a/raster/test/regress/check_raster_columns.sql +++ b/raster/test/regress/check_raster_columns.sql @@ -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; diff --git a/raster/test/regress/check_raster_columns_expected b/raster/test/regress/check_raster_columns_expected index 6bc4b0659..2c05c8fcb 100644 --- a/raster/test/regress/check_raster_columns_expected +++ b/raster/test/regress/check_raster_columns_expected @@ -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