Home PostgreSQL function name as variable similar to TG_NAME?
Reply: 1

PostgreSQL function name as variable similar to TG_NAME?

Rainer
1#
Rainer Published in 2018-01-11 17:28:12Z

Is there a special variable returning the name of a PostgreSQL function similar to special variable TG_NAME for triggers?

Vao Tsun
2#
Vao Tsun Reply to 2018-01-11 20:24:06Z

as of 9.4 I believe we have PG_CONTEXT:

https://www.postgresql.org/docs/current/static/plpgsql-control-structures.html

CREATE OR REPLACE FUNCTION inner_func() RETURNS integer AS $$
DECLARE
  stack text;
BEGIN
  GET DIAGNOSTICS stack = PG_CONTEXT;
  RAISE NOTICE E'--- Call Stack ---\n%', stack;
  RETURN 1;
END;
$$ LANGUAGE plpgsql;

for parsing the context for function name, use substring(stack from 'function (.*?) line') as in https://stackoverflow.com/a/32016935/5315974

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.29769 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO