]> granicus.if.org Git - postgis/commitdiff
Added DropGeometryColumn function
authorSandro Santilli <strk@keybit.net>
Fri, 4 Jun 2004 10:07:40 +0000 (10:07 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 4 Jun 2004 10:07:40 +0000 (10:07 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@587 b70326c6-7e19-0410-871a-916f4a2858ee

postgis.sql.in

index 9ed8d178101e8c30843ebaae0a0b3988a7efc3ff..ff040317e07d03722cecf42aca8ee32de0ca04e2 100644 (file)
@@ -2589,6 +2589,83 @@ BEGIN
 END;
 ' LANGUAGE 'plpgsql' WITH (isstrict);
 
+-----------------------------------------------------------------------
+-- DROPGEOMETRYTABLE
+--   <catalogue>, <schema>, <table>
+-----------------------------------------------------------------------
+--
+-- Drop a table and all its references in geometry_columns
+--
+-----------------------------------------------------------------------
+CREATEFUNCTION DropGeometryTable(varchar, varchar,varchar)
+       RETURNS text
+       AS 
+'
+DECLARE
+       catalog_name alias for $1; 
+       schema_name alias for $2;
+       table_name alias for $3;
+       real_schema name;
+
+BEGIN
+
+#if USE_VERSION >= 73
+       IF ( schema_name = '''' ) THEN
+               SELECT current_schema() into real_schema;
+       ELSE
+               real_schema = schema_name;
+       END IF;
+#endif // USE_VERSION >= 73
+
+       -- Remove refs from geometry_columns table
+       EXECUTE ''DELETE FROM geometry_columns WHERE '' ||
+#if USE_VERSION >= 73
+               ''f_table_schema = '' || quote_literal(real_schema) ||
+               '' AND '' ||
+#endif
+               '' f_table_name = '' || quote_literal(table_name);
+       
+       -- Remove table 
+       EXECUTE ''DROP TABLE ''
+#if USE_VERSION >= 73
+               || quote_ident(real_schema) || ''.'' ||
+#endif 
+               quote_ident(table_name);
+
+       RETURN
+#if USE_VERSION >= 73
+               real_schema || ''.'' ||
+#endif 
+               table_name ||'' dropped.'';
+       
+END;
+'
+LANGUAGE 'plpgsql' WITH (isstrict);
+
+-----------------------------------------------------------------------
+-- DROPGEOMETRYTABLE
+--   <schema>, <table>
+-----------------------------------------------------------------------
+--
+-- Drop a table and all its references in geometry_columns
+--
+-----------------------------------------------------------------------
+CREATEFUNCTION DropGeometryTable(varchar,varchar) RETURNS text AS 
+'SELECT DropGeometryTable('''',$1,$2)'
+LANGUAGE 'sql' WITH (isstrict);
+
+-----------------------------------------------------------------------
+-- DROPGEOMETRYTABLE
+--   <table>
+-----------------------------------------------------------------------
+--
+-- Drop a table and all its references in geometry_columns
+-- For PG>=73 use current_schema()
+--
+-----------------------------------------------------------------------
+CREATEFUNCTION DropGeometryTable(varchar) RETURNS text AS 
+'SELECT DropGeometryTable('''','''',$1)'
+LANGUAGE 'sql' WITH (isstrict);
 
 -----------------------------------------------------------------------
 -- UPDATE_GEOMETRY_STATS()