From: Sandro Santilli Date: Mon, 24 May 2004 13:02:22 +0000 (+0000) Subject: compat definition of fix_geometry_columns X-Git-Tag: pgis_0_8_2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9a23d48272dcac668b6835abc9498c1119743fc;p=postgis compat definition of fix_geometry_columns git-svn-id: http://svn.osgeo.org/postgis/trunk@556 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis.sql.in b/postgis.sql.in index 24b550022..f6d531266 100644 --- a/postgis.sql.in +++ b/postgis.sql.in @@ -807,6 +807,55 @@ CREATE FUNCTION get_proj4_from_srid(integer) RETURNS text AS LANGUAGE 'sql' WITH (iscachable,isstrict); +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- FIX_GEOMETRY_COLUMNS() +-- + +CREATE FUNCTION fix_geometry_columns() RETURNS text +AS +' +BEGIN + +#if USE_VERSION >= 73 + -- Since 7.3 schema support has been added. + -- Previous postgis versions used to put the database name in + -- the schema column. This needs to be fixed, so we set to the + -- empty string any schema value not existing in pg_namespace + -- + -- it would be better to find the correct schema name + UPDATE geometry_columns SET f_table_schema = ''public'' + WHERE f_table_schema is NULL or f_table_schema NOT IN + ( SELECT nspname::varchar FROM pg_namespace ); +#endif + +#if USE_VERSION < 75 + -- Until PG75 we mantain a custom statistic field + UPDATE geometry_columns SET attrelid = ( + SELECT c.oid + FROM pg_class c, pg_attribute a, pg_namespace n + WHERE c.relname = geometry_columns.f_table_name::name + AND a.attrelid = c.oid AND c.relnamespace = n.oid + AND a.attname = geometry_columns.f_geometry_column::name + AND n.nspname = geometry_columns.f_table_schema::name + ); + + UPDATE geometry_columns SET varattnum = ( + SELECT a.attnum + FROM pg_class c, pg_attribute a, pg_namespace n + WHERE n.nspname = geometry_columns.f_table_schema::name + AND c.relname = geometry_columns.f_table_name::name + AND a.attname = geometry_columns.f_geometry_column::name + AND a.attrelid = c.oid AND c.relnamespace = n.oid + ); +#endif + + RETURN ''geometry_columns table is now linked to the system tables''; + +END; +' +LANGUAGE 'plpgsql' ; + + -- - - - - - - - - - - - - - - - - - - - - - - - - - - - -- FIND_EXTENT( , ) @@ -2069,22 +2118,6 @@ INSERT INTO pg_amproc (amid, amopclaid, amproc, amprocnum) WHERE amname = 'gist' AND opcname = 'gist_geometry_ops' AND proname = 'ggeometry_same'; --- - - - - - - - - - - - - - - - - - - - - - - - - - - - --- FIX_GEOMETRY_COLUMNS() - -CREATE FUNCTION fix_geometry_columns() RETURNS text -AS -' -BEGIN - UPDATE geometry_columns SET attrelid = ( SELECT c.oid AS attrelid FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name - ); - UPDATE geometry_columns SET varattnum = ( SELECT a.attnum FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name - ); - - RETURN ''geometry_columns table is now linked to the system tables''; -END; -' -LANGUAGE 'plpgsql' ; #elif USE_VERSION == 72 @@ -2376,24 +2409,6 @@ INSERT INTO pg_amproc (amopclaid, amprocnum, amproc) and opcname = 'gist_geometry_ops' and proname = 'gbox_same'; --- - - - - - - - - - - - - - - - - - - - - - - - - - - - --- FIX_GEOMETRY_COLUMNS() - -CREATE FUNCTION fix_geometry_columns() RETURNS text -AS -' -BEGIN - - UPDATE geometry_columns SET attrelid = ( SELECT c.oid AS attrelid FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name - ); - UPDATE geometry_columns SET varattnum = ( SELECT a.attnum FROM pg_class c, pg_attribute a WHERE c.relname = geometry_columns.f_table_name::name AND a.attrelid = c.oid AND a.attname = geometry_columns.f_geometry_column::name - ); - - RETURN ''geometry_columns table is now linked to the system tables''; - -END; -' -LANGUAGE 'plpgsql' ; #elif USE_VERSION == 73 @@ -2570,48 +2585,6 @@ UPDATE pg_opclass SET opckeytype = (select oid from pg_type where typname = 'box') WHERE opcname = 'gist_geometry_ops'; --- - - - - - - - - - - - - - - - - - - - - - - - - - - - --- FIX_GEOMETRY_COLUMNS() --- --- Since 7.3 schema support has been added. --- Previous postgis versions used to put the database name in --- the schema column. This needs to be fixed, so we set to the --- empty string any schema value not existing in pg_namespace --- - -CREATE FUNCTION fix_geometry_columns() RETURNS text -AS -' -BEGIN - -- it would be better to find the correct schema name - UPDATE geometry_columns SET f_table_schema = ''public'' - WHERE f_table_schema is NULL or f_table_schema NOT IN - ( SELECT nspname::varchar FROM pg_namespace ); - - UPDATE geometry_columns SET attrelid = ( - SELECT c.oid - FROM pg_class c, pg_attribute a, pg_namespace n - WHERE c.relname = geometry_columns.f_table_name::name - AND a.attrelid = c.oid AND c.relnamespace = n.oid - AND a.attname = geometry_columns.f_geometry_column::name - AND n.nspname = geometry_columns.f_table_schema::name - ); - - UPDATE geometry_columns SET varattnum = ( - SELECT a.attnum - FROM pg_class c, pg_attribute a, pg_namespace n - WHERE n.nspname = geometry_columns.f_table_schema::name - AND c.relname = geometry_columns.f_table_name::name - AND a.attname = geometry_columns.f_geometry_column::name - AND a.attrelid = c.oid AND c.relnamespace = n.oid - ); - - RETURN ''geometry_columns table is now linked to the system tables''; - -END; -' -LANGUAGE 'plpgsql' ; - #elif USE_VERSION == 74 @@ -2813,48 +2786,6 @@ CREATE OPERATOR CLASS btree_geometry_ops FUNCTION 1 geometry_cmp (geometry, geometry); --- - - - - - - - - - - - - - - - - - - - - - - - - - - - --- FIX_GEOMETRY_COLUMNS() --- --- Since 7.3 schema support has been added. --- Previous postgis versions used to put the database name in --- the schema column. This needs to be fixed, so we set to the --- empty string any schema value not existing in pg_namespace --- - -CREATE FUNCTION fix_geometry_columns() RETURNS text -AS -' -BEGIN - -- it would be better to find the correct schema name - UPDATE geometry_columns SET f_table_schema = ''public'' - WHERE f_table_schema is NULL or f_table_schema NOT IN - ( SELECT nspname::varchar FROM pg_namespace ); - - UPDATE geometry_columns SET attrelid = ( - SELECT c.oid - FROM pg_class c, pg_attribute a, pg_namespace n - WHERE c.relname = geometry_columns.f_table_name::name - AND a.attrelid = c.oid AND c.relnamespace = n.oid - AND a.attname = geometry_columns.f_geometry_column::name - AND n.nspname = geometry_columns.f_table_schema::name - ); - - UPDATE geometry_columns SET varattnum = ( - SELECT a.attnum - FROM pg_class c, pg_attribute a, pg_namespace n - WHERE n.nspname = geometry_columns.f_table_schema::name - AND c.relname = geometry_columns.f_table_name::name - AND a.attname = geometry_columns.f_geometry_column::name - AND a.attrelid = c.oid AND c.relnamespace = n.oid - ); - - RETURN ''geometry_columns table is now linked to the system tables''; - - -END; -' -LANGUAGE 'plpgsql' ; #elif USE_VERSION == 75 @@ -3041,31 +2972,6 @@ CREATE OPERATOR CLASS btree_geometry_ops FUNCTION 1 geometry_cmp (geometry, geometry); --- - - - - - - - - - - - - - - - - - - - - - - - - - - - --- FIX_GEOMETRY_COLUMNS() --- --- Since 7.3 schema support has been added. --- Previous postgis versions used to put the database name in --- the schema column. This needs to be fixed, so we set to the --- empty string any schema value not existing in pg_namespace --- - -CREATE FUNCTION fix_geometry_columns() RETURNS text -AS -' -BEGIN - -- it would be better to find the correct schema name - UPDATE geometry_columns SET f_table_schema = ''public'' - WHERE f_table_schema is NULL or f_table_schema NOT IN - ( SELECT nspname::varchar FROM pg_namespace ); - - RETURN ''geometry_columns table is now linked to the system tables''; - - -END; -' -LANGUAGE 'plpgsql' ; - #endif // USE_VERSION == ...