Unable to call an overloaded UDF

Hanefi Onaldi <hanefi.onaldi@microsoft.com>

From: Hanefi Onaldi <Hanefi.Onaldi@microsoft.com>
To: "pgsql-novice@lists.postgresql.org" <pgsql-novice@lists.postgresql.org>
Date: 2022-05-12T23:38:29Z
Lists: pgsql-novice
Hello,

I have created 2 functions with the same name, and I am unable to call one of them. The first one does not have any parameters, and the second one has a single parameter with a default value. The error message I get makes sense to me, however the hint is not so helpful as I do not see any way I can do a type cast that will make Postgres call the function without any parameters in the definition.

Is there a way to make this work? Can this be a bug that needs fixing, or is it a known and intended feature?


Function definitions:

CREATE FUNCTION f() RETURNS int as $$ SELECT 1 $$ LANGUAGE SQL;
CREATE FUNCTION f(param int DEFAULT 1) RETURNS int as $$ SELECT param $$ LANGUAGE SQL;


Error message after I ran a simple query:

postgres # SELECT f();
ERROR:  42725: function f() is not unique
LINE 1: SELECT f();
               ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
LOCATION:  ParseFuncOrColumn, parse_func.c:577

Best,
Hanefi