13

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" 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.

I'm using PostgreSQL v. 9.1.5

4

3 に答える 3

7

トリガーの場合、 TG_NAMEを使用して、起動されたトリガー (トリガー関数ではない) の名前を取得します。

また、関数の実行の根本的な原因である、アプリケーションによって実行される最上位のcurrent_query()クエリを取得する必要があります。中間関数は表示されません。

それ以外の場合は、実際にはAFAIKではなく、デバッグ用に「現在の関数スタック」を出力したいときに、少し前に探しに行きました。他の人はもっと知っているかもしれません。

UPDATE : Pg 9.4 以降でPG_CONTEXTは、現在の関数名だけでなく、コール スタックにも使用できます。

于 2012-09-27T00:04:48.163 に答える
6

更新: コール スタックを取得する可能性は PostgreSQL 9.4 で利用可能です

いいえ、plpgsql 関数で現在実行されている関数の名前を取得する方法はありません。

数年前、コール スタックにアクセスするための関数を作成しました。これは orafce の一部です。スタックから最後の関数を取得できます

于 2012-09-27T11:20:00.300 に答える