Treating values of ST_Geometry as values of a subtype
If a spatial function returns a geometry whose static type is a super type, and if the geometry is passed to a function that accepts only geometries of a type that is subordinate to this super type, a compile-time exception is raised.
SQL00440N No function by the name "ST_POINTONSURFACE"
having compatible arguments was found in the function
path. SQLSTATE=42884
This message indicates that Db2 Spatial Extender could not find a function that is named ST_PointOnSurface and that has an input parameter of ST_Geometry.
To let geometries of a super type pass to functions that accept only subtypes of the super type, use the TREAT operator. As indicated earlier, ST_Union returns geometries of a static type of ST_Geometry. It can also return geometries of a dynamic subtype of ST_Geometry. Suppose, for example, that it returns a geometry with a dynamic type of ST_MultiPolygon. In that case, the TREAT operator requires that this geometry be used with the static type ST_MultiPolygon. This matches one of the data types of the input parameter of ST_PointOnSurface. If ST_Union does not return an ST_MultiPolygon value, Db2 Spatial Extender raises a runtime exception.
If a function returns a geometry of a super type, the TREAT operator generally can tell Db2 Spatial Extender to regard this geometry as a subtype of this super type. But be aware that this operation succeeds only if the subtype matches or is subordinate to a static subtype defined as an input parameter of the function to which the geometry is passed. If this condition is not met, Db2 Spatial Extender raises a run-time exception.
SELECT ST_AsText(ST_PerpPoints(TREAT(ST_Boundary(polygon) as ST_Curve)),
ST_Point(30.5, 65.3, 1)))
FROM polygon_table
SELECT TREAT(ST_Boundary(polygon) as ST_Curve)..
ST_PerpPoints(St_Point(30.5, 65.3, ))..ST_AsText()
FROM polygon_table