to_regprocedure()

A function converting a procedure/function name to an OID

to_regprocedure() is a system function for translating a procedure or function name to its OID.

to_regprocedure() was added in PostgreSQL 9.4.

Usage

to_regprocedure ( text ) → regprocedure

to_regprocedure() is equivalent to using the regprocedure cast, but returns NULL rather than raising an ERROR if no matching procedure or function is found.

The current search path is considered when evaluating the provided procedure or function name.

Note that to_regprocedure() requires the complete argument list of the specified procedure or function name.  See to_regproc() for an equivalent function which accepts the procedure or function name only.

Change history

Examples

Basic usage example for to_regprocedure():

postgres=# SELECT to_regprocedure('to_regprocedure(text)')::oid;
 to_regprocedure 
-----------------
            3479
(1 row)

Differentiating between functions with the same name but different signatures:

postgres=# CREATE FUNCTION foo()
             RETURNS INT
             LANGUAGE SQL
           AS $$
             SELECT 1;
           $$;
CREATE FUNCTION

postgres=# CREATE FUNCTION foo(integer)
             RETURNS INT
             LANGUAGE SQL
           AS $$
             SELECT 1 + $1;
           $$;
CREATE FUNCTION

postgres=# SELECT to_regprocedure('foo()')::oid;
 to_regprocedure 
-----------------
           16394
(1 row)

postgres=# SELECT to_regprocedure('foo(integer)')::oid;
 to_regprocedure 
-----------------
           16395
(1 row)

The provided name must be followed by a pair of parentheses even if a matching procedure or function exists with no parameters:

postgres=# SELECT to_regprocedure('foo');
ERROR:  expected a left parenthesis

to_regproc() accepts procedure and function names without any arguments, but will not return a result if more than one function is found with the provided name.

Categories

System function

See also

to_regproc()