SHARE
TWEET

Untitled

a guest May 16th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   DECLARE
  2.     selected_row jsonb;
  3.     second_set_of_selected_rows jsonb;
  4.     third_set_of_selected_rows jsonb;
  5.     the_result jsonb;
  6. BEGIN
  7.  
  8.     SELECT jsonb_agg(to_jsonb(x))
  9.     FROM (
  10.         SELECT
  11.         jsonb_build_object('id', table1.id,
  12.                    ...)
  13.         FROM some_table table1
  14.         WHERE id = id_sent_to_function
  15.         GROUP BY table1.id
  16.     ) x INTO selected_row;
  17.  
  18.     SELECT jsonb_agg(to_jsonb(y))
  19.     FROM (
  20.         SELECT
  21.         jsonb_build_object('id', table_2.id,
  22.                    ...)
  23.         FROM another_table table_2
  24.         JOIN a_map_table amt ON table_2.id = amt.some_id
  25.           AND amt.second_id = id_sent_to_function
  26.         GROUP BY table_2.id, amt.p::DOUBLE PRECISION / amt.q::DOUBLE PRECISION
  27.         ORDER BY some_field
  28.     ) y INTO second_set_of_selected_rows;
  29.  
  30.     SELECT jsonb_agg(to_jsonb(z))
  31.     FROM (
  32.         SELECT jsonb_build_object('id', table_3.id,
  33.                           ...)
  34.         FROM process table_3
  35.         WHERE table_3.id NOT IN (
  36.             SELECT xyz.id
  37.             FROM second_map_table smt
  38.             WHERE smt.methodology_id = id_sent_to_function)
  39.         GROUP BY table_3.id
  40.         ORDER BY another_field
  41.     ) z INTO third_set_of_selected_rows;
  42.  
  43.     the_result =
  44.         jsonb_build_object(
  45.                            'selected_row', selected_row,
  46.                            'second_set_of_selected_rows', second_set_of_selected_rows,
  47.                            'third_set_of_selected_rows', third_set_of_selected_rows
  48.                           );
  49.  
  50. RETURN RESULT;
  51. 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. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top