-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_old.sql
More file actions
30 lines (26 loc) · 986 Bytes
/
install_old.sql
File metadata and controls
30 lines (26 loc) · 986 Bytes
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
BEGIN;
DROP SCHEMA IF EXISTS http CASCADE;
CREATE SCHEMA http;
CREATE FUNCTION http.get_one_committee(name1 text, name2 text, name3 text, name4 text) RETURNS SETOF raw_committees AS $$
select *
from raw_committees
where committee_id in (2752,4212);
$$ LANGUAGE SQL;
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 array_to_json(array_agg(row_to_json(row, true)), true) 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;