0
我有一個函數從C庫調用函數。無論如何,我可以從調用C函數的Postgres函數中捕獲該異常?從C函數處理異常
下面是我打電話的功能:
-- 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功能不進入抗辯N塊如預期。
下面是我收到錯誤消息:
ERROR: Geometry type (MultiLineString) does not match column type (MultiPolygon)
********** Error **********
ERROR: Geometry type (MultiLineString) does not match column type (MultiPolygon)
SQL state: 22023
我已經試過用下面的函數做這件事,但它從來沒有進入異常塊:http://pastebin.com/egeAmepD – ChrisInCambo
我也嘗試在BEGIN/EXCEPTION塊中包裝ST_MakeValid調用,但沒有要麼提醒通知。我哪裏錯了? – ChrisInCambo
@ChrisInCambo這些是在你的問題中提到的有用的細節。請修改您的問題 - 在您的問題中,添加您正在獲取的錯誤消息**和您的PostgreSQL版本**的完整準確文本。現在解釋你的問題涉及到太多的猜測。請提供*詳細信息* - 你的函數是什麼,這個「C語言」函數是什麼等等。我猜對了,你正在談論一個簡單的PostGIS C函數,可以從SQL調用,還是這是別的? –