3

I'm trying to write a function to get the name of the function associated with a given regprocedure variable, as follows:

CREATE OR REPLACE FUNCTION get_funcname(_fn regprocedure)
 RETURNS text AS
$func$
 SELECT proname::text
 FROM pg_catalog.pg_proc AS p
 JOIN pg_catalog.pg_namespace AS ns
 ON p.pronamespace = ns.oid
 WHERE p.oid = _fn;
$func$ LANGUAGE sql;

I expect to get my_func in return for

SELECT get_funcname('my_func(text, variadic text[])');

However, the above is giving me the error:

ERROR: syntax error at or near "variadic"
LINE 1: SELECT get_funcname('my_func(text, variadic text[])');
 ^
CONTEXT: invalid type name "variadic text[]"

Can anyone help explain how to fix the function or syntax?

Evan Carroll
65.7k50 gold badges259 silver badges511 bronze badges
asked Mar 20, 2018 at 23:36

1 Answer 1

3

You have

ERROR: syntax error at or near "variadic"

From the docs,

VARIADIC parameters are input parameters, but are treated specially as described next.

That means you don't do anything special for VARIADIC parameters beyond what you would otherwise specify for input params. In your case, just drop that token,

SELECT get_funcname('my_func(text, text[])');

Can anyone help explain how to fix the function or syntax?

Sure.

WHERE p.oid = regexp_replace(_fn, ' VARIADIC ', ' ', 'i');
answered Mar 21, 2018 at 4:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.