我有一个从 C 库调用函数的函数。无论如何,我可以从调用 C 函数的 Postgres 函数中捕获该异常吗?
这是我正在调用的函数:
-- Function: public.st_makevalid(geometry)
-- DROP FUNCTION public.st_makevalid(geometry);
CREATE OR REPLACE FUNCTION public.st_makevalid(geometry)
RETURNS geometry AS
'$libdir/postgis-2.0', 'ST_MakeValid'
LANGUAGE c IMMUTABLE STRICT
COST 100;
ALTER FUNCTION public.st_makevalid(geometry) OWNER TO postgres;
COMMENT ON FUNCTION public.st_makevalid(geometry) IS 'args: input - Attempts to make an invalid geometry valid w/out loosing vertices.';
这是我从中调用它的函数:
CREATE OR REPLACE FUNCTION public.mango_repair(geometry)
RETURNS geometry AS
$BODY$
DECLARE
the_geom geometry := $1;
reason text := ST_IsValidReason(the_geom);
BEGIN
IF reason LIKE 'Self-intersection%' THEN
the_geom = ST_MakeValid(ST_Boundary(the_geom));
END IF;
RETURN the_geom;
EXCEPTION
WHEN OTHERS THEN
RAISE NOTICE 'something went wrong';
RETURN the_geom;
END;
$BODY$
LANGUAGE plpgsql STABLE STRICT
COST 100;
ALTER FUNCTION public.mango_repair(geometry) OWNER TO postgres;
这就是我从 SQL 中调用它的方式:
UPDATE "test_layer" SET the_geom = mango_repair(the_geom) WHERE NOT ST_IsValid(the_geom);
当我运行该 SQL 时,我收到以下错误,并且 mango_repair 函数没有按预期进入 EXCEPTION 块。
这是我收到的错误消息:
ERROR: Geometry type (MultiLineString) does not match column type (MultiPolygon)
********** Error **********
ERROR: Geometry type (MultiLineString) does not match column type (MultiPolygon)
SQL state: 22023