How To Loop Array List In Postegress D

Viewed 20

I Want to Loop Through A Array list in Postegres Sql

here is my query

do $$
    declare 
    jsn JSONB;
    j JSONB;
    arj JSONB[];
    begin
        jsn = to_jsonb('{"lst" : [{"a":"1"}, {"b":"2"}]'::TEXT);
        arj = jsn->>'lst';
        FOREACH j IN ARRAY arj LOOP
              SELECT j;
        END LOOP;
    end;
$$;

But When I Run This I am Getting This Error

ERROR:  FOREACH expression must not be null
CONTEXT:  PL/pgSQL function inline_code_block line 9 at FOREACH over array
SQL state: 22004
0 Answers
Related