Baker Baker - 5 months ago 18
SQL Question

Postgres show command in block of code

How can you use the

show
command in block of code?

I tried it several ways, but all I got was an error

do $$
begin
show enable_mergejoin; -- I need to to print this value (on/off)
end $$

Answer

show returns a result. In PL/pgSQL you can't "just" run a statement, the result of a statement must be stored in a variable:

do $$
declare
  l_value text;
begin
  show enable_mergejoin into l_value; -- retrieve and store the value
  raise notice '%', l_value; -- print the content
end $$
;