CREATE OR REPLACE FUNCTION my_function(input jsonb)
RETURNS jsonb
LANGUAGE plpgsql AS -- language declaration required
$func$
DECLARE
_key text;
_value text;
BEGIN
FOR _key, _value IN
SELECT jsonb_each_text($1)
LOOP
-- do some math operation on its corresponding value
RAISE NOTICE '%: %', _key, _value;
END LOOP;
RETURN input;
END
$func$;
For the function, if I call:
my_function('{"a":1, "b":2}');
It will raise notice that looks like (a, 1), (b, 2) in the message box.
However, if I change the code:
RAISE NOTICE '%: %', _key, _value;
into:
RAISE NOTICE '%', _key;
The same results will pop up.
While the code:
RAISE NOTICE '%', _value;
would pop up nothing. How did that happen?