From: Sandro Santilli Date: Thu, 19 Aug 2004 09:30:12 +0000 (+0000) Subject: rename_geometry_table_constraints() re-introduced to make X-Git-Tag: pgis_0_9_1~105 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58ddced4a11877811ec637adaa2511749eaca554;p=postgis rename_geometry_table_constraints() re-introduced to make constraint names conformant. git-svn-id: http://svn.osgeo.org/postgis/trunk@689 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis.sql.in b/postgis.sql.in index 2ec6cdbac..4a86b5f47 100644 --- a/postgis.sql.in +++ b/postgis.sql.in @@ -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_' +-- and 'enforce_srid_' +-- 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'; -----------------------------------------------------------------------