pggeodb.nancy.inra.fr/db_cefs - db_cefs on pggeodb.nancy.inra.fr
Previous topic Chapter index Next topic

Function: droptopology

 

 

Schema

topology

 

Owner

postgres

 

Descriptions

args: topology_schema_name - Use with caution: Drops a topology schema and deletes its reference from topology.topology table and references to tables in that schema from the geometry_columns table.

 

Options

Option

Value

Returns

text

Language

plpgsql

Parameters

atopology varchar

 

Definition

CREATE OR REPLACE FUNCTION topology.droptopology (
 atopology varchar
)
RETURNS text AS
$span$
DECLARE

 topoid integer;
 rec RECORD;
BEGIN
 -- Get topology id
 SELECT id INTO topoid
   FROM topology.topology WHERE name = atopology;

 IF NOT FOUND THEN
   RAISE EXCEPTION
'Topology % does not exist', quote_literal(atopology);
 END IF;

 RAISE NOTICE 'Dropping all layers from topology % (%)',
   quote_literal(atopology), topoid;

 -- Drop all layers in the topology
 FOR rec IN EXECUTE 'SELECT * FROM topology.layer WHERE '
   || ' topology_id = ' || topoid
 LOOP

   EXECUTE
'SELECT topology.DropTopoGeometryColumn('
     || quote_literal(rec.schema_name)
     || ','
     || quote_literal(rec.table_name)
     || ','
     || quote_literal(rec.feature_column)
     || ')';
 END LOOP;

 -- Delete record from topology.topology
 EXECUTE 'DELETE FROM topology.topology WHERE id = '
   || topoid;

 -- Drop the schema (if it exists)
 FOR rec IN SELECT * FROM pg_namespace WHERE text(nspname) = atopology
 LOOP
   EXECUTE
'DROP SCHEMA '||quote_ident(atopology)||' CASCADE';
 END LOOP;

 RETURN 'Topology ' || quote_literal(atopology) || ' dropped';
END
$span$
LANGUAGE
'plpgsql'
VOLATILE
RETURNS NULL ON NULL INPUT
SECURITY INVOKER
COST
100;

COMMENT ON FUNCTION topology.droptopology(atopology varchar)
IS 'args: topology_schema_name - Use with caution: Drops a topology schema and deletes its reference from topology.topology table and references to tables in that schema from the geometry_columns table.';

This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 13/03/2014 13:23
Previous topic Chapter index Next topic