-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_common-helpers_v1-2.sql
57 lines (45 loc) · 2.64 KB
/
update_common-helpers_v1-2.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
GROUP HEADERS GENERATED BY: https://patorjk.com/software/taag/#p=display&h=0&v=1&c=c&f=ANSI%20Shadow&t=STAGE%20FUNCS
SUB GROUP HEADERS GENERATED BY: https://patorjk.com/software/taag/#p=display&h=1&v=1&c=c&f=Banner3&t=permissions
*/
select *
from start_version_update('1.2', 'Delete fields from jsonb', _component := 'common_helpers',
_description := '');
/***
* ███╗ ██╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗███████╗███████╗ ████████╗███████╗██╗ ██╗████████╗
* ████╗ ██║██╔═══██╗██╔══██╗████╗ ████║██╔══██╗██║ ██║╚══███╔╝██╔════╝ ╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝
* ██╔██╗ ██║██║ ██║██████╔╝██╔████╔██║███████║██║ ██║ ███╔╝ █████╗ ██║ █████╗ ╚███╔╝ ██║
* ██║╚██╗██║██║ ██║██╔══██╗██║╚██╔╝██║██╔══██║██║ ██║ ███╔╝ ██╔══╝ ██║ ██╔══╝ ██╔██╗ ██║
* ██║ ╚████║╚██████╔╝██║ ██║██║ ╚═╝ ██║██║ ██║███████╗██║███████╗███████╗ ██║ ███████╗██╔╝ ██╗ ██║
* ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝╚══════╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
*
*/
create or replace function helpers.delete_jsonb_fields(_data jsonb, _fields_to_delete text[] default null)
returns jsonb
strict
immutable
parallel safe
cost 0.05
language plpgsql
as
$$
declare
field text;
__result jsonb;
begin
if _data is null then
return null;
elseif _fields_to_delete is null then
return _data;
end if;
__result := _data;
foreach field in array _fields_to_delete
loop
__result := __result - field;
raise info '%', field;
end loop;
return __result;
end;
$$;
select *
from stop_version_update('1.2', _component := 'common_helpers');