How to use Array in Array of Json

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to use Array in Array of Json

Monalee Bhandge-2
Dear Friends,
here I am sharing my actual use case.


-- Function: public.sample_json_array(json)

-- DROP FUNCTION public.sample_json_array(json);

CREATE OR REPLACE FUNCTION public.sample_json_array(vin_ip_param json)
  RETURNS void AS
$BODY$
Declare 
v_text text;
arr integer[];
cnt integer := 1;
val varchar;
BEGIN
/*
SELECT sample_json_array(' {
"vin_loc_cd" : [1, 2, 3],
"vin_comp_cd" : [5, 6, 7]
}
    ');
*/
DROP TABLE IF EXISTS my_loc ;

raise notice 'ABC %', (SELECT d.value FROM json_each_text(vin_ip_param) AS d WHERE d.key='vin_loc_cd' );

CREATE TEMP TABLE my_loc AS
(SELECT * from epps_admin.epps_location_mst lm
WHERE 
 lm.loc_cd In 
 (SELECT d.value FROM json_each_text(vin_ip_param) AS d WHERE d.key='vin_loc_cd' )
 ); 

END;

$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION public.sample_json_array(json)
  OWNER TO epps_programmer;

I WANT TO USE array variable "vin_loc_cd"  from input vin_ip_param json in my sql query.

Please provide solution for this scenario.