agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedHow to use Array in Array of Json
5+ messages / 3 participants
[nested] [flat]
* How to use Array in Array of Json
@ 2019-11-25 12:02 Monalee Bhandge <monalee.bhandge@epps-erp.com>
0 siblings, 2 replies; 5+ messages in thread
From: Monalee Bhandge @ 2019-11-25 12:02 UTC (permalink / raw)
To: pgsql-sql@lists.postgresql.org
Dear Friends,
My function definition is as:
CREATE OR REPLACE FUNCTION schema1.samplefun1(
vin_comp_cd smallint,
vin_div_cd smallint,
vin_loc_cd smallint[],
vin_bt_cd integer[],
)
Here instead of passing parameter I want to just send a single i/p in
Json[].
My problem is how to pass array in Json[] variable. And how to use in code.
Thanking You!
Monalee
Database Lead Engineer.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: How to use Array in Array of Json
@ 2019-11-25 16:13 Steve Midgley <science@misuse.org>
parent: Monalee Bhandge <monalee.bhandge@epps-erp.com>
1 sibling, 0 replies; 5+ messages in thread
From: Steve Midgley @ 2019-11-25 16:13 UTC (permalink / raw)
To: Monalee Bhandge <monalee.bhandge@epps-erp.com>; +Cc: pgsql-sql@lists.postgresql.org
On Mon, Nov 25, 2019 at 4:09 AM Monalee Bhandge <
monalee.bhandge@epps-erp.com> wrote:
> Dear Friends,
> My function definition is as:
>
> CREATE OR REPLACE FUNCTION schema1.samplefun1(
> vin_comp_cd smallint,
> vin_div_cd smallint,
> vin_loc_cd smallint[],
> vin_bt_cd integer[],
> )
>
> Here instead of passing parameter I want to just send a single i/p in
> Json[].
>
> My problem is how to pass array in Json[] variable. And how to use in code.
>
>
> I believe you want a json conversion function. The entire list is here:
https://www.postgresql.org/docs/current/functions-json.html
I'm guessing that the following function would be very useful to take a
single input json structure and convert it for insertion as single record
in a table: json_populate_record
I hope that is helpful?
Steve
^ permalink raw reply [nested|flat] 5+ messages in thread
* RE: How to use Array in Array of Json
@ 2019-11-25 16:14 2.andriychuk@gmail.com
parent: Monalee Bhandge <monalee.bhandge@epps-erp.com>
1 sibling, 1 reply; 5+ messages in thread
From: 2.andriychuk@gmail.com @ 2019-11-25 16:14 UTC (permalink / raw)
To: 'Monalee Bhandge' <monalee.bhandge@epps-erp.com>; pgsql-sql@lists.postgresql.org
Hi Monalee,
You can just use a json/jsonb variable. Content should be looking like this:
[
{“vin_comp_cd”: 1, “vin_div_cd”:11, “vin_array”: [{“vin_loc_cd”: 33, “vin_bt_cd”: 44}] },
…
{“vin_comp_cd”: N, “vin_div_cd”:NN, “vin_array”: [{“vin_loc_cd”: AA, “vin_bt_cd”: BB}] }
]
Or if “vin_loc_cd” and “vin_bt_cd” can be independent arrays if they are independent.
Best,
Igor
From: Monalee Bhandge <monalee.bhandge@epps-erp.com>
Sent: Monday, November 25, 2019 4:02 AM
To: pgsql-sql@lists.postgresql.org
Subject: How to use Array in Array of Json
Dear Friends,
My function definition is as:
CREATE OR REPLACE FUNCTION schema1.samplefun1(
vin_comp_cd smallint,
vin_div_cd smallint,
vin_loc_cd smallint[],
vin_bt_cd integer[],
)
Here instead of passing parameter I want to just send a single i/p in Json[].
My problem is how to pass array in Json[] variable. And how to use in code.
Thanking You!
Monalee
Database Lead Engineer.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: How to use Array in Array of Json
@ 2019-11-26 05:38 Monalee Bhandge <monalee.bhandge@epps-erp.com>
parent: 2.andriychuk@gmail.com
0 siblings, 0 replies; 5+ messages in thread
From: Monalee Bhandge @ 2019-11-26 05:38 UTC (permalink / raw)
To: 2.andriychuk@gmail.com; +Cc: pgsql-sql@lists.postgresql.org
Dear Friends,
Thanks for your email. But 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.
On Mon, Nov 25, 2019 at 9:44 PM <2.andriychuk@gmail.com> wrote:
> Hi Monalee,
>
>
>
> You can just use a json/jsonb variable. Content should be looking like
> this:
>
>
>
> [
>
> {“vin_comp_cd”: 1, “vin_div_cd”:11, “vin_array”: [{“vin_loc_cd”: 33,
> “vin_bt_cd”: 44}] },
>
> …
>
> {“vin_comp_cd”: N, “vin_div_cd”:NN, “vin_array”: [{“vin_loc_cd”: AA,
> “vin_bt_cd”: BB}] }
>
>
>
> ]
>
>
>
> Or if “vin_loc_cd” and “vin_bt_cd” can be independent arrays if they are
> independent.
>
>
>
> Best,
>
> Igor
>
>
>
> *From:* Monalee Bhandge <monalee.bhandge@epps-erp.com>
> *Sent:* Monday, November 25, 2019 4:02 AM
> *To:* pgsql-sql@lists.postgresql.org
> *Subject:* How to use Array in Array of Json
>
>
>
> Dear Friends,
>
> My function definition is as:
>
>
>
> CREATE OR REPLACE FUNCTION schema1.samplefun1(
>
> vin_comp_cd smallint,
>
> vin_div_cd smallint,
>
> vin_loc_cd smallint[],
>
> vin_bt_cd integer[],
>
> )
>
>
>
> Here instead of passing parameter I want to just send a single i/p in
> Json[].
>
>
>
> My problem is how to pass array in Json[] variable. And how to use in code.
>
>
>
>
>
> Thanking You!
>
> Monalee
>
> Database Lead Engineer.
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* How to use Array in Array of Json
@ 2019-11-27 12:11 Monalee Bhandge <monalee.bhandge@epps-erp.com>
0 siblings, 0 replies; 5+ messages in thread
From: Monalee Bhandge @ 2019-11-27 12:11 UTC (permalink / raw)
To: pgsql-sql@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2019-11-27 12:11 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25 12:02 How to use Array in Array of Json Monalee Bhandge <monalee.bhandge@epps-erp.com>
2019-11-25 16:13 ` Steve Midgley <science@misuse.org>
2019-11-25 16:14 ` 2.andriychuk@gmail.com
2019-11-26 05:38 ` Monalee Bhandge <monalee.bhandge@epps-erp.com>
2019-11-27 12:11 How to use Array in Array of Json Monalee Bhandge <monalee.bhandge@epps-erp.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox