functions/GET_CALLER_FUNCTION.pg_sql
Functions
| GET_CALLER_FUNCTION | 
|---|
| Returns the name of the function that called the function that called this function.    Syntax:GET_CALLER_FUNCTION ()Return values:Copyright:Thiemo Kellner, 2018 -Webpage:https://www.sourceforge.net/projects/pgloggerVersion Info:$Id: GET_CALLER_FUNCTION.pg_sql 3 2018-03-30 15:56:40Z thiemo $Additional Info:License LGPLv3TODO:Once PostgreSQL supports packages, integrate this function into one. For the time being, it should get installed within a schema on its own and no execution grants should be given on it.Once HyperSQL supports a license tag, convert the corresponding info tag into one.
 | 
Source
001: \echo Start functions/GET_CALLER_FUNCTION.pg_sql
002: 
003: 004: 005: 006: 007: 008: 009: 010: 011: 012: 013: 014: 015: 016: 
017: create or replace function GET_CALLER_FUNCTION()
018:   returns name
019:   language plpgsql
020:   volatile
021: 022: 023: 024:   set search_path = :SCHEMA_NAME, public
025:   as
026: $body$
027:     declare
028:         C_PATTERN_SPLIT_SIGN constant text :=
029:           E'(\\r\\n|\\r|\\n)+';
030:         C_PATTERN_FOR_FUNCTION_NAME constant text :=
031:           E'^.*\\W(\\w+\\([^)]*\\)|inline_code_block).*$';
032:         C_REPLACEMENT_STRING constant text := E'\\1';
033: 
034:         V_STACK text;
035:         V_LINE_LOOKED_FOR text;
036:     begin
037:         GET DIAGNOSTICS V_STACK = pg_context;
038: 039: 040: 041: 042: 043: 044: 045:         with FUNCTION_STACK as (
046:             select LINE,
047:                    lead(LINE, 1) over (partition by 1) as NEXT_LINE
048:               from regexp_split_to_table(
049:                        V_STACK,
050:                        C_PATTERN_SPLIT_SIGN
051:                    ) as LINE
052:              where LINE ~ '^PL/pgSQL function .*$'
053:         )
054:         select NEXT_LINE into V_LINE_LOOKED_FOR
055:           from FUNCTION_STACK
056:          where LINE ~* '^.* (debug|log|info|notice|warning|exception)\(.*$';
057: 
058:         return regexp_replace(
059:                    V_LINE_LOOKED_FOR,
060:                    C_PATTERN_FOR_FUNCTION_NAME,
061:                    C_REPLACEMENT_STRING
062:                );
063:     end;
064: $body$;
065: 
066: comment on function GET_CALLER_FUNCTION() is 'Returns the name of the function that called the function that called this function.
067: $Header: svn+ssh://thiemo@svn.code.sf.net/p/pglogger/code/functions/GET_CALLER_FUNCTION.pg_sql 3 2018-03-30 15:56:40Z thiemo $';
068: 
069: commit; 070: 
071: \echo End functions/GET_CALLER_FUNCTION.pg_sql
  Generated by 
HyperSQL v3.9.8 at Wed Jul  4 07:48:48 2018