I write a lot of debugging code in plpgsql along the lines:
RAISE NOTICE 'var1 = %', var1;
(there can be more than one variable to print out).
Is it possible to avoid having to repeat the variable var1
every time by writing a PostgreSQL function (say myprint
) so that
SELECT myprint(var1);
will generate the same output as RAISE NOTICE 'var1 = %', var1;
?
The problem is that I know how to get the value of var1
in the function but I don't know how to get the name var1
. Is there some call-stack or context magic in plpgsql that can provide the name of the variable passed to myprint
?
(This is with PostgreSQL 12.1 or later)