-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsicob_pexecute.sql
More file actions
61 lines (59 loc) · 2.01 KB
/
Copy pathsicob_pexecute.sql
File metadata and controls
61 lines (59 loc) · 2.01 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
61
SET CLIENT_ENCODING TO 'utf8';
CREATE OR REPLACE FUNCTION public.sicob_pexecute(opt json)
RETURNS json
LANGUAGE plpgsql
AS $function$
DECLARE
conn text;
watcherconn text;
sql text;
result text;
out json := '{}';
BEGIN
/*
opt := json_build_object(
'sql','select pg_sleep(10),topology.DropTopology(''fix_f20181128cgabedff840e77f'')'
);
*/
sql := COALESCE((opt->>'sql')::text,'');
conn := sicob_dblink_connect('');
--> send the query asynchronously using the dblink connection
--> check for errors dispatching the query
IF dblink_send_query(conn, sql) = 0 THEN
out := json_build_object('error', dblink_error_message(conn) );
result := dblink_disconnect(conn);
--> Send error to error clallback function
IF COALESCE((opt->>'error')::text,'') <> '' THEN
sql := Format('SELECT %s(%s::json);',(opt->>'error')::text, QUOTE_LITERAL(out::text));
RAISE DEBUG 'Running %', sql;
EXECUTE sql;
END IF;
RETURN out;
END IF;
out := json_build_object('conn', conn);
PERFORM dblink_disconnect(conn);
/*
opt := opt::jsonb || jsonb_build_object(
'conn', conn);
sql := Format('SELECT sicob_presult(%s::json)', QUOTE_LITERAL(opt::text) );
--> send the query asynchronously using the dblink connection
--> check for errors dispatching the query
IF dblink_send_query(conn, sql) = 0 THEN
out := json_build_object('error', dblink_error_message(conn) );
PERFORM dblink_disconnect(conn);
--> Send error to error clallback function
IF COALESCE((opt->>'error')::text,'') <> '' THEN
sql := Format('SELECT %s(%s);',(opt->>'error')::text, QUOTE_LITERAL(out::text));
RAISE DEBUG 'Running %', sql;
EXECUTE sql;
END IF;
RETURN out;
END IF;
*/
RETURN out;
EXCEPTION
WHEN others THEN
RAISE EXCEPTION 'geoVision [sicob_pexecute], opt: %, % (%)', opt, SQLERRM, SQLSTATE;
END;
$function$