-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyFunctions.sql
More file actions
60 lines (39 loc) · 1.12 KB
/
MyFunctions.sql
File metadata and controls
60 lines (39 loc) · 1.12 KB
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
58
59
60
--drop extension if exists plpython3u cascade;
create extension if not exists plpython3u;
drop function if exists fnc_python_nodejs_base(module text, arguments text);
create or replace function fnc_python_nodejs_base(module text, arguments text default null) returns text as
$$
from MyFunctions import py_node
argumentsAux = str(arguments or '')
#plpy.notice(module)
#plpy.notice(arguments)
#plpy.notice(argumentsAux)
output = py_node(module, argumentsAux)
return output
$$
language plpython3u;
drop function if exists fnc_python_nodejs(module text, arguments text);
create or replace function fnc_python_nodejs(module text, arguments text default null) returns jsonb as
$body$
declare
vRetorno jsonb;
begin
vRetorno := fnc_python_nodejs_base(module, arguments);
if vRetorno ? 'data' then
return vRetorno->'data';
else
raise exception '%', vRetorno->'error';
end if;
end
$body$
language 'plpgsql';
/*
select
fnc_python_nodejs(
'httpClient',
jsonb_build_object(
'method', 'get',
'url', 'https://brasilapi.com.br/api/cep/v2/14770000'
)::text
);
*/