Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL plpgsql get current procedures oid

Is it possible to get the current OID within a function? Like:

CREATE FUNCTION foo()
 RETURNS numeric
 LANGUAGE plpgsql
AS '
  BEGIN
    return THIS_FUNCTIONS_OID;
  END
';

I need this, because I created function foo within different schemas so the functions name is not helpful here.

like image 349
maroonyw Avatar asked Aug 14 '15 09:08

maroonyw


1 Answers

I guess you are looking smth like

return select oid from pg_proc where proname='$0';

I doubt you can get it as variable. You can get the name from current_query(), but it will be very not reliable... Unless you define function name as first argument each time you call it :), then you can use $1, but it is not much reliable either...

like image 161
Vao Tsun Avatar answered Oct 14 '22 01:10

Vao Tsun