-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_new.sql
More file actions
61 lines (52 loc) · 1.6 KB
/
install_new.sql
File metadata and controls
61 lines (52 loc) · 1.6 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
BEGIN;
DROP SCHEMA IF EXISTS http CASCADE;
CREATE SCHEMA http;
CREATE FUNCTION http.get_args2(name1 text, name2 text, name3 text, name4 text, OUT name1 json) AS
'SELECT row_to_json(row(name1 , name2 , name3 , name4));'
LANGUAGE SQL;
CREATE FUNCTION http.get_top_committee_data(name1 text, name2 text, numRec text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM campaign_detail
ORDER BY total DESC
LIMIT numRec::int) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get_committee_data(name1 text, name2 text, commName text, name4 text) RETURNS json AS $$
DECLARE
result json;
BEGIN
SELECT array_to_json(array_agg(row_to_json(qres, true)), true)
FROM
(SELECT *
FROM campaign_detail
WHERE candidate_name=commName
ORDER BY total DESC) qres
INTO result;
return result;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION http.get(aschema text, afunction text, apath text, auser text) RETURNS json AS $$
DECLARE
args text;
result json;
BEGIN
SELECT array_to_string(array_agg(
(SELECT quote_literal(a[1]) || coalesce('::' || b[2], '')
FROM regexp_split_to_array(row, E'::') AS a,
regexp_split_to_array(row, E'::') AS b)
), ',')
FROM unnest(regexp_split_to_array(apath, E'\/')) AS row INTO args;
args := format('SELECT * FROM %I.%I(%L, %s) as row;', aschema, 'get_' || afunction, auser, args);
RAISE NOTICE '%', args;
EXECUTE args into result;
RETURN result;
END;
$$ LANGUAGE plpgsql;
COMMIT;