How to use Array in Array of Json

From: Monalee Bhandge <monalee(dot)bhandge(at)epps-erp(dot)com>
To: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: How to use Array in Array of Json
Date: 2019-11-27 12:11:08
Message-ID: CAErOoCeuzbjqEgCnSEr87tbHmUpXb7gXGsLiZKTtsmK-+QhOYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

Browse pgsql-sql by date

  From Date Subject
Next Message Iaam Onkara 2019-12-01 22:54:02 Solving my query needs with Rank and may be CrossTab
Previous Message github kran 2019-11-27 01:22:31 Re: PostGreSQL Replication and question on maintenance