SHARE
TWEET
Untitled
a guest
May 16th, 2019
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- DECLARE
- selected_row jsonb;
- second_set_of_selected_rows jsonb;
- third_set_of_selected_rows jsonb;
- the_result jsonb;
- BEGIN
- SELECT jsonb_agg(to_jsonb(x))
- FROM (
- SELECT
- jsonb_build_object('id', table1.id,
- ...)
- FROM some_table table1
- WHERE id = id_sent_to_function
- GROUP BY table1.id
- ) x INTO selected_row;
- SELECT jsonb_agg(to_jsonb(y))
- FROM (
- SELECT
- jsonb_build_object('id', table_2.id,
- ...)
- FROM another_table table_2
- JOIN a_map_table amt ON table_2.id = amt.some_id
- AND amt.second_id = id_sent_to_function
- GROUP BY table_2.id, amt.p::DOUBLE PRECISION / amt.q::DOUBLE PRECISION
- ORDER BY some_field
- ) y INTO second_set_of_selected_rows;
- SELECT jsonb_agg(to_jsonb(z))
- FROM (
- SELECT jsonb_build_object('id', table_3.id,
- ...)
- FROM process table_3
- WHERE table_3.id NOT IN (
- SELECT xyz.id
- FROM second_map_table smt
- WHERE smt.methodology_id = id_sent_to_function)
- GROUP BY table_3.id
- ORDER BY another_field
- ) z INTO third_set_of_selected_rows;
- the_result =
- jsonb_build_object(
- 'selected_row', selected_row,
- 'second_set_of_selected_rows', second_set_of_selected_rows,
- 'third_set_of_selected_rows', third_set_of_selected_rows
- );
- RETURN RESULT;
- END;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

