Postgresql – How use raise notice in nested and sub-function

debuggingfunctionspostgresql

I'm using PgAdmin to create multiple pgsql functions.
I'm beginner on this environment.
I'm using 'raise notice' to help me for debugging phase.

I have two functions with 'raise notice' statement.
The first function calls the second function.

I can show the 'raise notice' statement for the first function.
I can't show the 'raise notice' statement for the second function. In place, the console show blank lines for each 'raise notice' that should be shown.

Function 1 – Example :

raise notice 'Function 1 executing';    -- This raise notice works
PERFORM public.function_2();

Function 2 – Example :

raise notice 'Function 2 is now running';   -- This raise notice doesn't work

Is it possible to do what I want?

Best Answer

Yes it is possible. I have tested the following with PG 12.2 and with psql CLI:

show client_min_messages;
client_min_messages 
---------------------
notice
(1 row) 
create or replace function f2 () returns text
as
$$
declare
begin
 raise notice 'Function 2 is now running';
 return 'f2: OK';
end;
$$
language plpgsql;
CREATE FUNCTION
create or replace function f1 () returns text
as
$$
declare
begin
 raise notice 'Function 1 executing';
 perform f2();
 return 'f1: OK';
end;
$$
language plpgsql;
CREATE FUNCTION
select f1();
psql:t2f.sql:27: NOTICE:  Function 1 executing
psql:t2f.sql:27: NOTICE:  Function 2 is now running
   f1   
--------
 f1: OK
(1 row)