]> granicus.if.org Git - postgis/commitdiff
rename_geometry_table_constraints() re-introduced to make
authorSandro Santilli <strk@keybit.net>
Thu, 19 Aug 2004 09:30:12 +0000 (09:30 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 19 Aug 2004 09:30:12 +0000 (09:30 +0000)
constraint names conformant.

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

postgis.sql.in

index 2ec6cdbac6d0cb4692c2b2da7ea9e3cfede1398d..4a86b5f47da0f893daaaff9cba43e5d62387d3c7 100644 (file)
@@ -417,16 +417,33 @@ LANGUAGE 'sql' WITH (iscachable,isstrict);
 -----------------------------------------------------------------------
 -- RENAME_GEOMETRY_TABLE_CONSTRAINTS()
 -----------------------------------------------------------------------
--- This function has been obsoleted for the difficulty in
--- finding attribute on which the constraint is applied.
--- AddGeometryColumn will name the constraints in a meaningful
--- way, but nobody can rely on it since old postgis versions did
--- not do that.
+-- This function renames geometrytype and srid constraints
+-- applied to spatial tables by old AddGeometryColumn to
+-- new meaningful name 'enforce_geotype_<geomcolname>'
+-- and 'enforce_srid_<geomcolname>'
+-- Needs to be called only when upgrading from postgis < 0.8.3
 -----------------------------------------------------------------------
 CREATEFUNCTION rename_geometry_table_constraints() RETURNS text
 AS 
 '
-SELECT ''rename_geometry_table_constraint() is obsoleted''::text
+UPDATE pg_constraint 
+       SET conname = textcat(''enforce_geotype_'', a.attname)
+       FROM pg_attribute a
+       WHERE
+               a.attrelid = conrelid
+               AND a.attnum = conkey[1]
+               AND consrc LIKE ''((geometrytype(%) = %'';
+
+UPDATE pg_constraint
+       SET conname = textcat(''enforce_srid_'', a.attname)
+       FROM pg_attribute a
+       WHERE
+               a.attrelid = conrelid
+               AND a.attnum = conkey[1]
+               AND consrc LIKE ''(srid(% = %)'';
+
+SELECT ''spatial table constraints renamed''::text;
+
 ' LANGUAGE 'SQL';
 
 -----------------------------------------------------------------------