Sample Header Ad - 728x90

How to get the name of a variable instead of its value in plpgsql?

2 votes
0 answers
195 views
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)
Asked by tinlyx (3820 rep)
Jan 1, 2020, 05:57 PM
Last activity: Dec 26, 2021, 02:44 AM