I am trying to access a variable from a parent block from within a nested block using postgresql's plpgsql as follows
DO $outer-block$
DECLARE
test_variable text DEFAULT "test";
BEGIN
DO $inner-block$
BEGIN
RAISE NOTICE '%',test_variable;
END;
$inner-block$;
END;
$outer-block$;
When I try to run this, it tells me that "the column test_variable doesn't exist", so I suppose that this variable is not in scope when the inner block is given control, is there any way to access it from within the nested block?
(I checked up this question: How to access outer scope variables from a function in PostgreSQL?, which was sort of similar, but in that case it's trying to access the outer block variable from whitin a function, which is a persistent database object, and it would in a way be trying to create a closure, that is not what I am doing here, since I want to access the outer block's scope from within a one-time execution inner block, which might make a difference, but I don't know it for certain)