Hi
jsonb with subscripting support can be used as a dictionary object in plpgsql.
Can be nice to have support for iteration over a set of tuples (key, value).
Some like
FOREACH fieldvar [ KEY keyvar] IN DICTIONARY sourceexpr [VALUE searchexpr]
LOOP
END LOOP;
and for JSON arrays
FOREACH var IN ARRAY jsonval
LOOP
END LOOP
Example:
dict jsonb DEFAULT '{"a", "a1", "b", "b1"}
v text; k text;
j jsonb;
BEGIN
FOREACH v KEY k IN DICTIONARY dict
LOOP
RAISE NOTICE '%=>%', k, v; -- a=>a1\nb=>b1
END LOOP;
--
FOREACH j IN DICTIONARY dict
LOOP
RAISE NOTICE '%', j; -- {"a":"a1"}\n{"b":"b1"}
END LOOP;
The goal is to support fast iteration over some non atomic objects different from arrays.
Maybe some background of XMLTABLE and JSON_TABLE functions can be used there.
Comments, notes?
Regards
Pavel