Revision 13384
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
2100 | 2100 |
|
2101 | 2101 |
|
2102 | 2102 |
-- |
2103 |
-- Name: loop_ignore_errors(text, text, anyelement); Type: FUNCTION; Schema: util; Owner: - |
|
2104 |
-- |
|
2105 |
|
|
2106 |
CREATE FUNCTION loop_ignore_errors(iter_sql text, loop_body_sql text, loop_type_null anyelement DEFAULT NULL::text) RETURNS void |
|
2107 |
LANGUAGE plpgsql |
|
2108 |
AS $$ |
|
2109 |
DECLARE |
|
2110 |
errors_ct integer = 0; |
|
2111 |
loop_var loop_type_null%TYPE; |
|
2112 |
BEGIN |
|
2113 |
FOR loop_var IN SELECT * FROM util.eval2set(iter_sql, loop_type_null) |
|
2114 |
LOOP |
|
2115 |
BEGIN |
|
2116 |
EXECUTE loop_body_sql USING loop_var; |
|
2117 |
EXCEPTION |
|
2118 |
WHEN OTHERS THEN |
|
2119 |
errors_ct = errors_ct+1; |
|
2120 |
PERFORM util.raise_error_warning(SQLERRM); |
|
2121 |
END; |
|
2122 |
END LOOP; |
|
2123 |
IF errors_ct > 0 THEN |
|
2124 |
-- can't raise exception because this would roll back the transaction |
|
2125 |
PERFORM util.raise_error_warning('there were '||errors_ct |
|
2126 |
||' errors: see the WARNINGs for details'); |
|
2127 |
END IF; |
|
2128 |
END; |
|
2129 |
$$; |
|
2130 |
|
|
2131 |
|
|
2132 |
-- |
|
2103 | 2133 |
-- Name: ltrim_nl(text); Type: FUNCTION; Schema: util; Owner: - |
2104 | 2134 |
-- |
2105 | 2135 |
|
Also available in: Unified diff
schemas/util.sql: added loop_ignore_errors()