Re: possible proposal plpgsql GET DIAGNOSTICS oid = PG_ROUTINE_OID

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: possible proposal plpgsql GET DIAGNOSTICS oid = PG_ROUTINE_OID
Дата
Msg-id CAFj8pRBEwu3FwFvjOn0oB9hO0Rnipzko9r0bHj248CJgowza6w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: possible proposal plpgsql GET DIAGNOSTICS oid = PG_ROUTINE_OID  (Julien Rouhaud <rjuju123@gmail.com>)
Ответы Re: possible proposal plpgsql GET DIAGNOSTICS oid = PG_ROUTINE_OID  (Kirk Wolak <wolakk@gmail.com>)
Список pgsql-hackers
hi



st 8. 2. 2023 v 7:33 odesílatel Julien Rouhaud <rjuju123@gmail.com> napsal:
On Tue, Feb 07, 2023 at 08:48:22PM +0100, Pavel Stehule wrote:
>
> I have a question about the possibility of simply getting the name of the
> currently executed function. The reason for this request is simplification
> of writing debug messages.
>
> GET DIAGNOSTICS _oid = PG_ROUTINE_OID;
> RAISE NOTICE '... % ... %', _oid, _oid::regproc::text;
>
> The advantage of this dynamic access to function name is always valid value
> not sensitive to some renaming or moving between schemas.
>
> I am able to separate a name from context, but it can be harder to write
> this separation really robustly. It can be very easy to enhance the GET
> DIAGNOSTICS statement to return the oid of currently executed function.
>
> Do you think it can be useful feature?

+1, it would have been quite handy in a few of my projects.

it can looks like that

create or replace function foo(a int)
returns int as $$
declare s text; n text; o oid;
begin
  get diagnostics s = pg_current_routine_signature,
                  n = pg_current_routine_name,
                  o = pg_current_routine_oid;
  raise notice 'sign:%,  name:%,  oid:%', s, n, o;
  return a;
end;
$$ language plpgsql;
CREATE FUNCTION
(2023-02-08 09:04:03) postgres=# select foo(10);
NOTICE:  sign:foo(integer),  name:foo,  oid:16392
┌─────┐
│ foo │
╞═════╡
│  10 │
└─────┘
(1 row)


The name - pg_routine_oid can be confusing, because there is not clean if it is oid of currently executed routine or routine from top of exception

Regards

Pavel
Вложения

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

Предыдущее
От: Amit Kapila
Дата:
Сообщение: Re: Logical replication timeout problem
Следующее
От: John Naylor
Дата:
Сообщение: Re: bitscan forward/reverse on Windows