FluentDBFluentDB
PostgreSQL errors

PostgreSQL: function is not unique

ERRORSQLSTATE 42725ambiguous_function
ERROR: function <name>(<args>) is not unique

More than one function matches your call after type resolution, so Postgres cannot choose. Cast the arguments so exactly one overload fits, or schema-qualify the function.

What this error means

When several overloaded functions could accept your arguments, often because the literals are untyped, Postgres cannot pick a single best match and refuses with a HINT to add explicit type casts.

It can also happen when two functions with the same name exist in different schemas on your search_path.

How to fix it

01

Ambiguous argument types

Cast the arguments so only one overload matches.

sql
SELECT myfunc($1::numeric);
02

Two functions share the name across schemas

Schema-qualify the call.

sql
SELECT app.myfunc(1);

How to avoid it next time

  • Cast arguments to concrete types when calling overloaded functions.
  • Avoid defining functions with the same name in multiple schemas on the path.

Frequently asked questions

What does 'Could not choose a best candidate function' mean?

It is the HINT: several overloads match your arguments equally. Add casts so one is the clear match.

How is this different from 'function does not exist'?

That means no overload matches. This means more than one matches and Postgres cannot choose.

Stop struggling with SQL

Use FluentDB, the AI database client for macOS.