-- In this example the boundary_test table is created with two columns:
-- geotype defined as a varchar, and g1 defined as the superclass geometry.
-- The INSERT statements that follow insert each one of the subclass 
-- geometries. The ST_Boundary function retrieves the boundary of each
-- subclass stored in the g1 geometry column. Note that the dimension of
-- the resulting geometry is always one less than the input geometry.
-- Points and multipoints always result in a boundary that is an empty
-- geometry, dimension -1. Linestrings and multilinestrings return
-- a multipoint boundary, dimension 0. A polygon or multipolygon always
-- returns a multilinestring boundary, dimension 1.

CREATE TABLE boundary_test (geotype varchar(20),
                            g1      ST_Geometry);

INSERT INTO boundary_test VALUES( 
   'Point', ST_PointFromText('point (10.02 20.01)',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Linestring', 
   ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Polygon', 
   ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94, 10.02 20.01))',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Multipoint', 
  ST_MPointFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Multilinestring', 
   ST_MLineFromText('multilinestring ((10.02 20.01,10.32 23.98,11.92 25.64), (9.55 23.75,15.36 30.11))',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Multipolygon', 
   ST_MPolyFromText('multipolygon (((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94,10.02 20.01)),((51.71 21.73,73.36 27.04,71.52 32.87,52.43 31.90,51.71 21.73)))',1000) 
);

SELECT geotype, ST_Boundary(g1)  
   FROM boundary_test;
