1-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2--
3-- PostGIS - Spatial Types for PostgreSQL
4-- http://postgis.net
5--
6-- Copyright (C) 2012 Sandro Santilli <strk@kbt.io>
7--
8-- This is free software; you can redistribute and/or modify it under
9-- the terms of the GNU General Public Licence. See the COPYING file.
10--
11-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12
13-- {
14--  Clear the contents of a TopoGeometry
15--
16-- }{
17CREATE OR REPLACE FUNCTION topology.clearTopoGeom(tg topology.TopoGeometry)
18  RETURNS topology.TopoGeometry
19AS
20$$
21DECLARE
22  topology_info RECORD;
23  sql TEXT;
24BEGIN
25
26  -- Get topology information
27  SELECT id, name FROM topology.topology
28    INTO topology_info
29    WHERE id = topology_id(tg);
30  IF NOT FOUND THEN
31      RAISE EXCEPTION 'No topology with id "%" in topology.topology', topology_id(tg);
32  END IF;
33
34  -- Clear the TopoGeometry contents
35  sql := 'DELETE FROM ' || quote_ident(topology_info.name)
36        || '.relation WHERE layer_id = '
37        || layer_id(tg)
38        || ' AND topogeo_id = '
39        || id(tg);
40#ifdef POSTGIS_TOPOLOGY_DEBUG
41    RAISE DEBUG '%', sql;
42#endif
43  EXECUTE sql;
44
45  RETURN tg;
46
47END
48$$
49LANGUAGE 'plpgsql' VOLATILE STRICT;
50-- }
51
52