Revision 11695
Added by Aaron Marcuse-Kubitza about 11 years ago
schemas/util.sql | ||
---|---|---|
1114 | 1114 |
|
1115 | 1115 |
|
1116 | 1116 |
-- |
1117 |
-- Name: force_recreate(text, text[]); Type: FUNCTION; Schema: util; Owner: - |
|
1118 |
-- |
|
1119 |
|
|
1120 |
CREATE FUNCTION force_recreate(cmd text, users text[] DEFAULT NULL::text[]) RETURNS void |
|
1121 |
LANGUAGE plpgsql |
|
1122 |
AS $_$ |
|
1123 |
DECLARE |
|
1124 |
PG_EXCEPTION_DETAIL text; |
|
1125 |
recreate_users_cmd text = util.save_drop_views(users); |
|
1126 |
BEGIN |
|
1127 |
PERFORM util.eval(cmd); |
|
1128 |
PERFORM util.eval(recreate_users_cmd); |
|
1129 |
EXCEPTION |
|
1130 |
WHEN dependent_objects_still_exist THEN |
|
1131 |
IF users IS NOT NULL THEN RAISE; END IF; -- save_drop_views() didn't fix it |
|
1132 |
GET STACKED DIAGNOSTICS PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL; |
|
1133 |
users = array(SELECT * FROM util.regexp_matches_group( |
|
1134 |
PG_EXCEPTION_DETAIL, '(?m)^view (.*) depends on table .*$')); |
|
1135 |
IF util.is_empty(users) THEN RAISE; END IF; |
|
1136 |
PERFORM util.force_recreate(cmd, users); |
|
1137 |
END; |
|
1138 |
$_$; |
|
1139 |
|
|
1140 |
|
|
1141 |
-- |
|
1142 |
-- Name: FUNCTION force_recreate(cmd text, users text[]); Type: COMMENT; Schema: util; Owner: - |
|
1143 |
-- |
|
1144 |
|
|
1145 |
COMMENT ON FUNCTION force_recreate(cmd text, users text[]) IS 'idempotent |
|
1146 |
|
|
1147 |
users: not necessary to provide this because it will be autopopulated'; |
|
1148 |
|
|
1149 |
|
|
1150 |
-- |
|
1117 | 1151 |
-- Name: force_update_view(text, text); Type: FUNCTION; Schema: util; Owner: - |
1118 | 1152 |
-- |
1119 | 1153 |
|
Also available in: Unified diff
schemas/util.sql: added force_recreate(), for use by sync_analytical_stem_to_view(). this uses the new `GET STACKED DIAGNOSTICS` in PostgreSQL 9.3 to access the DETAIL section of the dependent_objects_still_exist error.