Search Postgresql Archives

Re: Function name variable within a non-trigger function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 24, 2005 at 10:44:19AM -0500, Berend Tober wrote:
> I know that within a trigger function the functin name can be referenced 
> by the special variable TG_NAME, so I could include raise an exception 
> that identified its source with a line like:
> 
>      RAISE EXCEPTION ''ERROR IN %'', TG_NAME;

TG_NAME contains the name of the trigger, not the name of the
function the trigger calls.  If you define a trigger as

  CREATE TRIGGER footrig BEFORE INSERT ON foo
    FOR EACH ROW EXECUTE PROCEDURE trigfunc();

then the error message from the code you posted will be

  ERROR:  ERROR IN footrig

A trigger function can find its name by querying pg_trigger and pg_proc:

  funcname := p.proname
              FROM pg_trigger AS t JOIN pg_proc AS p ON p.oid = t.tgfoid
              WHERE t.tgrelid = TG_RELID AND t.tgname = TG_NAME;

> Is there a similar set of special variables defined for "normal", i.e., 
> non-trigger functions, too?

I'm not aware of a way for a non-trigger PL/pgSQL function to find
out its name or oid.  Functions written in C can do it.

-- 
Michael Fuhr


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux