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

gefragt vor 2 Jahren218 Aufrufe
1 Antwort
0

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

beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen