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

已提問 2 年前檢視次數 218 次
1 個回答
0

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

已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南