Getting name of the current function inside of the function with plpgsql

前端 未结 3 1305
北荒
北荒 2021-01-17 16:28

Is there anyway from within a plpgsql function that you can get the name of the function? Or even the OID of the function?

I know there are some \"special\" variab

3条回答
  •  没有蜡笔的小新
    2021-01-17 16:58

    For triggers use TG_NAME to get the name of the trigger (not the trigger function) fired.

    You also have current_query() to get the top level query executed by the application, the root cause for your function's execution. It won't show you any intermediate functions.

    Otherwise, not really AFAIK and I did go looking for it a while ago when I wanted to print a "current function stack" for debugging. Others may know more.

    UPDATE: In Pg 9.4 and above you can also use PG_CONTEXT to the call stack, but not just the current function name.

提交回复
热议问题