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

posta 2 anni fa218 visualizzazioni
1 Risposta
0

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

con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande