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

前端 未结 3 1263
北荒
北荒 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:45

    As of Postgres 9.4, the below function will return its own name:

    CREATE OR REPLACE FUNCTION your_schema.get_curr_fx_name()
    RETURNS text AS  $$
    DECLARE
      stack text; fcesig text;
    BEGIN
      GET DIAGNOSTICS stack = PG_CONTEXT;
      fcesig := substring(stack from 'function (.*?) line');
      RETURN fcesig::regprocedure::text;
    END;
    $$ LANGUAGE plpgsql;
    

提交回复
热议问题