Propagate segment errcodes to dispatcher
The errcode thrown in an ereport() on a segment was passed back to the dispatcher, but then dropped and replaced with a default errcode of ERRCODE_DATA_EXCEPTION. This works for most situations, but when trapping errors the exact errcode must be propagated. This extends the API to extract the errcode as well. The below case illustrates the previous issue: CREATE TABLE test1(id int primary key); CREATE TABLE test2(id int primary key); INSERT INTO test1 VALUES(1); INSERT INTO test2 VALUES(1); CREATE OR REPLACE FUNCTION merge_table() RETURNS void AS $$ DECLARE v_insert_sql varchar; BEGIN v_insert_sql :='INSERT INTO test1 SELECT * FROM test2'; EXECUTE v_insert_sql; EXCEPTION WHEN unique_violation THEN RAISE NOTICE 'unique_violation'; END; $$ LANGUAGE plpgsql volatile; SELECT merge_table();
Showing
想要评论请 注册 或 登录