title: postgreSQL : oracle sqlerrm equivalent of postgres
body: <p>I'm new to PostgreSQL. I have experience in oracle. In oracle , to find the exact error, I use code 'dbms_output.put_line(sqlerrm)' . Here I have a postgresql function returning an integer value</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.fn_sqltest(
    p_id integer)
    RETURNS integer
    LANGUAGE 'plpgsql'
  
    COST 100
    VOLATILE 
  
   AS $BODY$ 
   Declare
     n integer;
   begin  
  
       select off_id into n from office 
         where per_id=p_id;
  
       return n ;
  
   exception when others then
  
       return -1;
  
   end;
  
   $BODY$;
  
   ALTER FUNCTION public.fn_sqltest(character varying)
    OWNER TO postgres;
  </code></pre>
  
  <p>I call this function as below</p>
  
  <pre><code>DO $$ 
  
  DECLARE
    ae integer;
  
  BEGIN 
  
    ae:=fn_sqltest(10);
    RAISE NOTICE 'exception: % %  ', sqlstate ,  sqlerrm ;
    RAISE NOTICE 'Return value is: % ', ae;
  
  END $$;
  </code></pre>
  
  <p>and I get the error </p>
  
  <blockquote>
    <p>ERROR: column "sqlstate" does not exist</p>
  </blockquote>
  
  <p>How can I show the exact error message like sqlerrm in oracle.</p>