getting the output of delete statement in UDF in postgres In Postgres in a user defined function I do

execute format('delete from table where session_id = %L', id);


ran without execute postgres (may) return(s) the following:

DELETE 0


Is there any way I could get this output in the user defined function? What I am looking is something like:

execute format('delete from table where session_id = %L', id) into log;
You can use the GET DIAGNOSTICS command for this purpose.  A quick example:

DO $$
DECLARE i integer; 
BEGIN
    DELETE FROM event1;
    GET DIAGNOSTICS i = ROW_COUNT;
    RAISE NOTICE 'DELETE %', i;
END;
$$;


For DELETE statements, the only useful variable is ROW_COUNT, for INSERTs there is also RESULT_OID.

Set the error level after the RAISE to your choice and set the logging configuration accordingly.