-- The valid_test table is created with the columns geotype and g1
-- The geotype column stores the name of the geometry subclass
-- stored in the g1 geometry column.

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

-- The INSERT statements insert a sample subclass into the valid_test table.

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

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

INSERT INTO valid_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 valid_test VALUES( 
   'MultiPoint',
   ST_MPointFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)',1000)
);

INSERT INTO valid_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 valid_test VALUES( 
   'MultiPolygon',
   ST_MPolyFromText ('multipolygon (((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.64,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)
);

-- The SELECT statement lists the subclass name stored
-- in the geotype column with the dimension of that geotype.

SELECT ST_IsValid(g1) If_valid 
FROM valid_test;
