Re: Function name variable within a non-trigger function

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Function name variable within a non-trigger function
Дата
Msg-id 20051126023638.GA85424@winnie.fuhr.org
обсуждение исходный текст
Ответ на Function name variable within a non-trigger function  (Berend Tober <btober@seaworthysys.com>)
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Jaime Casanova
Дата:
Сообщение: Re: howto create dynamic table name in plpgsql function.
Следующее
От: Wes
Дата:
Сообщение: Re: Deadlock Detected (revisited)