How to use the super type as a JSON-containing argument to a procedure and use the JSON elements in a FROM clause of a SELECT

0

Hello, I need to pass a JSON argument in a procedure to use it in a FROM clause of a SELECT.

So far I try :

CREATE OR REPLACE PROCEDURE public.test_json(Tparam VARCHAR(256)) LANGUAGE plpgsql AS $$ DECLARE elem VARCHAR(256);

BEGIN

DROP TABLE IF EXISTS temp ;

CREATE TABLE temp (jsonfield super);

INSERT INTO temp VALUES (JSON_PARSE(Tparam));

SELECT jsonfield."accountIds"[0] INTO elem FROM temp ;

SELECT myfield FROM mytable WHERE myfield=elem ;

END; $$

But I would prefer to do it directly : « SELECT jsonfield."accountIds"[0] INTO elem FROM Tparam ; »

If you a any idea I will be very happy.

Pascal J

asked 2 years ago212 views
1 Answer
0

Without solution we give up stored procedures and choose to use embedded sql in our code.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions