to_regproc()

A function converting a procedure/function name to an OID

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

to_regproc() was added in PostgreSQL 9.4.

Usage

to_regproc ( text ) → regproc

to_regproc() is equivalent to using the regproc 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_regproc() operates on procedure or function names only. NULL is returned if a function exists with the same name but differing signatures. See to_regprocedure() for an equivalent function which considers the respective procedure or function arguments.

Change history

Examples

Basic usage example for to_regproc():

postgres=# SELECT to_regproc('to_regproc')::oid;
 to_regproc
------------
       3494
(1 row)

If a function is "overloaded", i.e. multiple versions of a function exist with the same name but different argument forms, NULL is returne:

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

postgres=# SELECT to_regproc('foo')::oid;
 to_regproc
------------
      17536
(1 row)

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

postgres=# SELECT to_regproc('foo')::oid;
 to_regproc
------------

(1 row)

Categories

System function

See also

to_regprocedure()