使用plpgsql在函数内部获取当前函数的名称 [英] Getting name of the current function inside of the function with plpgsql

查看:60
本文介绍了使用plpgsql在函数内部获取当前函数的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从plpgsql函数中是否可以获取该函数的名称?甚至函数的OID?

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

我知道在plpgsql中有一些特殊"变量(例如FOUND),但是似乎没有任何办法可以做到这一点. (尽管,我已经阅读了用C语言编写的函数似乎有可能的地方).并不是很关键,但这会使我做的事情变得更好/更不脆弱.

I know there are some "special" variables (such as FOUND) within plpgsql, but there doesn't seem to be any way of getting this. (Although, I've read where it seems to be possible if your function is written in C). It's not critical, but it would make something I'm doing a little nicer/less fragile.

我正在使用PostgreSQL 9.1.5版

I'm using PostgreSQL v. 9.1.5

推荐答案

对于触发器,请使用

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

您还具有current_query()来获取应用程序执行的顶级查询,这是函数执行的根本原因.它不会显示任何中间功能.

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.

否则,不是真正的AFAIK,我前一阵子想打印当前函数堆栈"进行调试时确实去找了它.其他人可能知道更多.

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 :在Pg 9.4及更高版本中,您还可以使用PG_CONTEXT来调用堆栈,而不仅仅是当前函数名.

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

这篇关于使用plpgsql在函数内部获取当前函数的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆